-
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.
cgen, checker: fix comptimeselector passing to generic argument (vlan…
- Loading branch information
Showing
3 changed files
with
50 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
struct Struc { | ||
a string | ||
b int | ||
c ?string | ||
d ?int | ||
} | ||
|
||
pub struct Count { | ||
mut: | ||
total int | ||
} | ||
|
||
// count_chars count json sizen whithout new encode | ||
pub fn (mut count Count) count_chars[T](val T) { | ||
$if val is $option { | ||
workaround := val | ||
if workaround != none { | ||
count.count_chars(val) | ||
} | ||
} $else $if T is $struct { | ||
count.chars_in_struct(val) | ||
} $else { | ||
} | ||
} | ||
|
||
// chars_in_struct | ||
fn (mut count Count) chars_in_struct[T](val T) { | ||
$for field in T.fields { | ||
va := val.$(field.name) | ||
count.count_chars(va) // works | ||
count.count_chars(val.$(field.name)) // Not works | ||
} | ||
} | ||
|
||
fn test_main() { | ||
struc := Struc{} | ||
mut count := Count{} | ||
count.count_chars(struc) | ||
assert true | ||
} |