Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checker: fix autocast in complex if condtions 2 (#18702)
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
type MySumType = S1 | S2 | ||
|
||
struct Info { | ||
name string | ||
} | ||
|
||
struct Node { | ||
left MySumType | ||
} | ||
|
||
struct S1 { | ||
is_info bool | ||
info Info | ||
} | ||
|
||
fn (s1 S1) is_info() bool { | ||
return s1.is_info | ||
} | ||
|
||
struct S2 { | ||
field2 string | ||
} | ||
|
||
fn get_name(name string) string { | ||
return name | ||
} | ||
|
||
fn test_autocast_in_if_conds() { | ||
node := Node{ | ||
left: MySumType(S1{ | ||
is_info: false | ||
info: Info{'foo'} | ||
}) | ||
} | ||
|
||
a := 22 | ||
|
||
if a > 0 && node.left is S1 && !node.left.is_info && get_name(node.left.info.name) == 'foo' | ||
&& !node.left.is_info() { | ||
println('ok') | ||
assert true | ||
} else { | ||
assert false | ||
} | ||
} |