-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checker: fix some specific interface generic inference within generic…
…s struct and method (vlang#20932)
- Loading branch information
1 parent
5f5e948
commit bbdd6c5
Showing
2 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
vlib/v/tests/generics_interface_with_generic_method_using_generic_struct_test.v
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
struct Store[Z] { | ||
mut: | ||
event_handlers []IEventHandler[Z] | ||
} | ||
|
||
fn (mut me Store[Z]) add_event_handler(event_handler IEventHandler[Z]) { | ||
me.event_handlers << IEventHandler[Z](event_handler) | ||
} | ||
|
||
interface IEventHandler[Z] { | ||
mut: | ||
apply(event Z) | ||
} | ||
|
||
struct UserEvent {} | ||
|
||
struct UserEventHandler {} | ||
|
||
pub fn (mut me UserEventHandler) apply(event UserEvent) {} | ||
|
||
fn test_generic_interface_with_method_using_generic_struct() { | ||
mut s := Store[UserEvent]{} | ||
s.add_event_handler(UserEventHandler{}) | ||
assert s.event_handlers.len > 0 | ||
} |