-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parser: fixed struct methods and receiver use different generic names…
- Loading branch information
Showing
2 changed files
with
43 additions
and
4 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
34 changes: 34 additions & 0 deletions
34
vlib/v/tests/generics_method_with_diff_generic_names_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,34 @@ | ||
// for issue: 20363 | ||
// The generic name used by the methods and receiver is different from the generic name defined by the struct. | ||
struct Foo[T] { | ||
field T | ||
} | ||
|
||
fn new_foo[U](arg U) Foo[U] { | ||
return Foo[U]{arg} | ||
} | ||
|
||
fn test_using_diff_generic_names() { | ||
foo := new_foo(1) | ||
foo.method_1('hello') | ||
foo.method_2('hello') | ||
} | ||
|
||
fn (f Foo[U]) method_1(arg string) { | ||
assert arg == 'hello' | ||
} | ||
|
||
fn (f Foo[U]) method_2[U](arg string) { | ||
assert arg == 'hello' | ||
} | ||
|
||
// for issue: 20365 | ||
// The generic name used by the `str()` method and receiver is different from the generic name defined by the struct. | ||
fn (f Foo[U]) str[U]() string { | ||
return 'hello' | ||
} | ||
|
||
fn test_str_override() { | ||
foo := new_foo(1) | ||
assert '${foo}' == 'hello' | ||
} |