| 1 | struct Context {} |
| 2 | |
| 3 | struct App { |
| 4 | mut: |
| 5 | called bool |
| 6 | } |
| 7 | |
| 8 | fn (mut app App) before_request(mut ctx Context) { |
| 9 | app.called = true |
| 10 | } |
| 11 | |
| 12 | interface HasBeforeRequest[X] { |
| 13 | mut: |
| 14 | before_request(mut ctx X) |
| 15 | } |
| 16 | |
| 17 | fn check_before_request[A, X](mut app A) bool { |
| 18 | mut ctx := Context{} |
| 19 | $if A is HasBeforeRequest[X] { |
| 20 | app.before_request(mut ctx) |
| 21 | return true |
| 22 | } $else { |
| 23 | return false |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | fn test_comptime_if_is_generic_interface_with_generic_type_param() { |
| 28 | mut app := App{} |
| 29 | assert check_before_request[App, Context](mut app) |
| 30 | assert app.called |
| 31 | } |
| 32 | |