....
This commit is contained in:
25
examples/issue-0003.sx
Normal file
25
examples/issue-0003.sx
Normal file
@@ -0,0 +1,25 @@
|
||||
// Issue: enum literal inference in match expression used as assignment RHS
|
||||
// When a match expression is assigned to a field with a known enum type,
|
||||
// the enum literals in case arms should infer their type from the assignment target.
|
||||
|
||||
Color :: enum {
|
||||
red;
|
||||
green;
|
||||
blue;
|
||||
none;
|
||||
}
|
||||
|
||||
Thing :: struct {
|
||||
color: Color;
|
||||
}
|
||||
|
||||
main :: () {
|
||||
t : Thing = ---;
|
||||
value : u8 = 1;
|
||||
t.color = if value == {
|
||||
case 1: .red; // error: cannot infer enum type for literal
|
||||
case 2: .green;
|
||||
case 3: .blue;
|
||||
else: .none;
|
||||
};
|
||||
}
|
||||
18
examples/issue-0004-defs.sx
Normal file
18
examples/issue-0004-defs.sx
Normal file
@@ -0,0 +1,18 @@
|
||||
#import "modules/std.sx";
|
||||
|
||||
Color :: struct {
|
||||
r, g, b, a: u8;
|
||||
}
|
||||
|
||||
COLOR_WHITE :: Color.{ r = 255, g = 255, b = 255, a = 255 };
|
||||
|
||||
// Additional case: struct constant with enum-typed fields
|
||||
HAlign :: enum { leading; center; trailing; }
|
||||
VAlign :: enum { top; center; bottom; }
|
||||
|
||||
Alignment :: struct {
|
||||
h: HAlign;
|
||||
v: VAlign;
|
||||
}
|
||||
|
||||
ALIGN_CENTER :: Alignment.{ h = .center, v = .center };
|
||||
20
examples/issue-0004.sx
Normal file
20
examples/issue-0004.sx
Normal file
@@ -0,0 +1,20 @@
|
||||
// Issue: top-level constants from imported files are not visible
|
||||
// COLOR_WHITE works after fix, but ALIGN_CENTER (struct with enum fields) does not.
|
||||
// Error: undefined identifier 'ALIGN_CENTER'
|
||||
|
||||
#import "modules/std.sx";
|
||||
#import "examples/issue-0004-defs.sx";
|
||||
|
||||
Thing :: struct {
|
||||
color: Color;
|
||||
alignment: Alignment;
|
||||
|
||||
make :: () -> Thing {
|
||||
Thing.{ color = COLOR_WHITE, alignment = ALIGN_CENTER };
|
||||
}
|
||||
}
|
||||
|
||||
main :: () {
|
||||
t := Thing.make();
|
||||
print("{}\n", t.color.r);
|
||||
}
|
||||
Reference in New Issue
Block a user