Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checker: fix .variant smartcast on non-comptime variables (#20575)
- Loading branch information
Showing
5 changed files
with
44 additions
and
12 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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
#!/usr/bin/env expect | ||
source "common.tcl" | ||
|
||
expect "Break on * comptime_variant_int in ${test_file}:7" | ||
expect "${test_file}:7 vdbg> " | ||
send "p a\n" | ||
expect "a = 0 (int)" | ||
expect "Break on * comptime_variant in ${test_file}:6" | ||
expect "${test_file}:6 vdbg> " | ||
send "p arg\n" | ||
expect "arg = 0 (int)" | ||
send "c\n" | ||
expect "${test_file}:6 vdbg> " | ||
send "p arg\n" | ||
expect "arg = foo (string)" | ||
send "q\n" | ||
expect eof |
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
type MySum = int | string | ||
|
||
fn comptime_variant_int() { | ||
a := MySum(int(0)) | ||
$for v in MySum.variants { | ||
if a is v { | ||
fn comptime_variant(arg MySum) { | ||
$for v in arg.variants { | ||
if arg is v { | ||
$dbg; | ||
dump(a) | ||
dump(arg) | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
comptime_variant_int() | ||
comptime_variant(MySum(int(0))) | ||
comptime_variant(MySum('foo')) | ||
} |
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,22 @@ | ||
type TestSum = bool | f64 | int | string | ||
|
||
fn test_main() { | ||
a := TestSum(true) | ||
$for v in TestSum.variants { | ||
if a is v { | ||
$if a is bool { | ||
assert a == true | ||
} | ||
$if a is string { | ||
assert a == '' | ||
} | ||
$if a is f64 { | ||
assert a == 0 | ||
} | ||
$if a is int { | ||
assert a == 0 | ||
} | ||
} | ||
} | ||
assert true | ||
} |