Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checker: fix generic struct field with default fn_type value (fix #19011
) (#19014)
- Loading branch information
Showing
4 changed files
with
113 additions
and
51 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
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
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
30 changes: 30 additions & 0 deletions
30
vlib/v/tests/generics_struct_field_with_default_fn_type_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,30 @@ | ||
[heap] | ||
struct BloomFilter1[T] { | ||
hash_func fn (T) u32 = unsafe { nil } // hash function, input [T] , output u32 | ||
table_size int // every entry is one-bit, packed into `table` | ||
num_functions int // 1~16 | ||
} | ||
|
||
[heap] | ||
struct BloomFilter2[T] { | ||
// TODO V bug | ||
hash_func fn (T) u32 = default_cb[T] // hash function, input [T] , output u32 | ||
table_size int // every entry is one-bit, packed into `table` | ||
num_functions int // 1~16 | ||
mut: | ||
table []u8 | ||
} | ||
|
||
fn default_cb[T](x T) u32 { | ||
return 22 | ||
} | ||
|
||
fn test_generic_struct_field_with_default_fn_type() { | ||
filter1 := BloomFilter1[int]{} | ||
println(filter1) | ||
assert true | ||
|
||
filter2 := BloomFilter2[int]{} | ||
println(filter2.hash_func(11)) | ||
assert filter2.hash_func(11) == 22 | ||
} |