diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2023-08-11 22:21:33 -0400 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2023-08-12 01:57:07 -0400 |
| commit | ffc116de78dee6db8b3f2e0474f21bd88ef3895c (patch) | |
| tree | 6de533285533bf39714a975a6c45a532a52a738e /test/cases/compile_errors | |
| parent | 5e0107fbce8f33f84af232c3edc912a81615175f (diff) | |
| download | zig-ffc116de78dee6db8b3f2e0474f21bd88ef3895c.tar.gz zig-ffc116de78dee6db8b3f2e0474f21bd88ef3895c.zip | |
AstGen: fix src loc for invalid if expression rls coercions
Closes #12509
Diffstat (limited to 'test/cases/compile_errors')
| -rw-r--r-- | test/cases/compile_errors/invalid_if_expr_result_location_coercion.zig | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/cases/compile_errors/invalid_if_expr_result_location_coercion.zig b/test/cases/compile_errors/invalid_if_expr_result_location_coercion.zig new file mode 100644 index 0000000000..c49a3287b1 --- /dev/null +++ b/test/cases/compile_errors/invalid_if_expr_result_location_coercion.zig @@ -0,0 +1,32 @@ +export fn invalidRuntimeThen(cond: bool) u0 { + const invalid: u16 = 256; + const result: u8 = if (cond) invalid else 0; + return result; +} + +export fn invalidComptimeThen() u0 { + const invalid: u16 = 256; + const result: u8 = if (true) invalid else 0; + return result; +} + +export fn invalidRuntimeElse(cond: bool) u0 { + const invalid: u16 = 256; + const result: u8 = if (cond) 0 else invalid; + return result; +} + +export fn invalidComptimeElse() u0 { + const invalid: u16 = 256; + const result: u8 = if (false) 0 else invalid; + return result; +} + +// error +// backend=stage2 +// target=native +// +// :3:34: error: type 'u8' cannot represent integer value '256' +// :9:34: error: type 'u8' cannot represent integer value '256' +// :15:41: error: type 'u8' cannot represent integer value '256' +// :21:42: error: type 'u8' cannot represent integer value '256' |
