Followup from #1107.
This test passes now:
test"switch prongs with cases with identical payload types" {
constUnion=union(enum) {
A: usize,
B: isize,
C: usize,
};
constS=struct {
fndoTheTest() void {
doTheSwitch1(Union{ .A=8 });
doTheSwitch2(Union{ .B=-8 });
}
fndoTheSwitch1(u: Union) void {
switch (u) {
.A, .C=>|e| {
expect(@typeOf(e) ==usize);
expect(e==8);
},
.B=>|e|@panic("fail"),
}
}
fndoTheSwitch2(u: Union) void {
switch (u) {
.A, .C=>|e|@panic("fail"),
.B=>|e| {
expect(@typeOf(e) ==isize);
expect(e==-8);
},
}
}
};
S.doTheTest();
comptimeS.doTheTest();
}But this diff:
- A: usize,+ A: u8,
B: isize,
- C: usize,+ C: u16,
Gives this error:
/home/andy/downloads/zig/build/test.zig:18:28: error: capture group with incompatible types
.A, .C => |e| {
^
/home/andy/downloads/zig/build/test.zig:18:17: note: type 'u8' here
.A, .C => |e| {
^
/home/andy/downloads/zig/build/test.zig:18:21: note: type 'u16' here
.A, .C => |e| {
^
However, I propose this should work. peer type resolution would make the type of e be u16 and everything is fine. Likewise a T could be grouped with a ?T.
Followup from #1107.
This test passes now:
But this diff:
Gives this error:
However, I propose this should work. peer type resolution would make the type of
ebeu16and everything is fine. Likewise aTcould be grouped with a?T.