-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
Milestone
Description
Zig Version
0.11.0-dev.3387+f04e65bc0
Steps to Reproduce and Observed Behavior
This doesn't compile
pub fn main() void {
const S = struct { x: u8 };
var x = for ([_]S{.{ .x = 42 }}) |s| {
break s;
} else S{ .x = 42 };
_ = x;
}and the compiler error is this
src\main.zig:3:13: error: incompatible types: 'main.main.S' and 'void'
var x = for ([_]S{.{ .x = 42 }}) |s| {
^~~
src\main.zig:4:15: note: type 'main.main.S' here
break s;
The weird thing is if we annotate x:
pub fn main() void {
const S = struct { x: u8 };
var x: S = for ([_]S{.{ .x = 42 }}) |s| {
break s;
} else S{ .x = 42 };
_ = x;
}It compiles fine.
Expected Behavior
Both of these code snippets should compile.
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior