-
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolve peer types of optionals and interned values (#2193)
- Loading branch information
1 parent
43bece5
commit 2078220
Showing
2 changed files
with
110 additions
and
4 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,44 @@ | ||
const S = struct { | ||
int: i64, | ||
float: f32, | ||
}; | ||
|
||
pub fn main() void { | ||
var runtime_bool: bool = undefined; | ||
|
||
const widened_int_0 = if (runtime_bool) @as(i8, undefined) else @as(i16, undefined); | ||
// ^^^^^^^^^^^^^ (i16)() | ||
|
||
const widened_int_1 = if (runtime_bool) @as(i16, undefined) else @as(i8, undefined); | ||
// ^^^^^^^^^^^^^ (i16)() | ||
|
||
const optional_0 = if (runtime_bool) @as(S, undefined) else @as(?S, undefined); | ||
// ^^^^^^^^^^ (?S)() | ||
|
||
const optional_1 = if (runtime_bool) @as(?S, undefined) else @as(S, undefined); | ||
// ^^^^^^^^^^ (?S)() | ||
|
||
const optional_2 = if (runtime_bool) null else @as(S, undefined); | ||
// ^^^^^^^^^^ (?S)() | ||
|
||
const optional_3 = if (runtime_bool) @as(S, undefined) else null; | ||
// ^^^^^^^^^^ (?S)() | ||
|
||
const optional_4 = if (runtime_bool) null else @as(?S, undefined); | ||
// ^^^^^^^^^^ (?S)() | ||
|
||
const optional_5 = if (runtime_bool) @as(?S, undefined) else null; | ||
// ^^^^^^^^^^ (?S)() | ||
|
||
// Use @compileLog to verify the expected type with the compiler: | ||
@compileLog(widened_int_0); | ||
@compileLog(widened_int_1); | ||
@compileLog(optional_0); | ||
@compileLog(optional_1); | ||
@compileLog(optional_2); | ||
@compileLog(optional_3); | ||
@compileLog(optional_4); | ||
@compileLog(optional_5); | ||
|
||
runtime_bool = undefined; | ||
} |