This commit is contained in:
agra
2026-02-24 19:31:10 +02:00
parent 7a381e1b4c
commit 9dba8eef5b
4 changed files with 72 additions and 4 deletions

23
examples/issue-0006.sx Normal file
View File

@@ -0,0 +1,23 @@
// Issue: match on u8 value with enum result assigned to typed field
// The switch value is u8 but case constants are s64 (default int literal type).
// Compiler should cast case constants to match the switch value type.
// LLVM error: Switch constants must all be same type as switch value!
out :: (str: string) -> void #builtin;
Button :: enum {
none;
left;
middle;
right;
}
main :: () {
val : u8 = 2;
result : Button = if val == {
case 1: .left;
case 2: .middle;
case 3: .right;
else: .none;
};
}

39
examples/issue-0007.sx Normal file
View File

@@ -0,0 +1,39 @@
// Issue: chained method call on struct field operates on a copy
// `a.field.method()` where method takes *Self creates a temporary copy of `field`
// instead of borrowing `a.field` as a pointer.
// The mutation is lost because it modifies the copy, not the original.
out :: (str: string) -> void #builtin;
Counter :: struct {
value: s64;
inc :: (self: *Counter) {
self.value += 1;
}
}
Parent :: struct {
counter: Counter;
}
main :: () {
p := Parent.{ counter = Counter.{ value = 0 } };
// This should increment p.counter.value, but the mutation is lost:
p.counter.inc();
if p.counter.value == 0 {
out("BUG: p.counter.value is still 0 after inc()\n");
} else {
out("OK: p.counter.value is 1\n");
}
// Workaround: take explicit pointer
cp := @p.counter;
cp.inc();
if p.counter.value == 1 {
out("OK: workaround via pointer works\n");
}
}

View File

@@ -1,4 +1,7 @@
#import c {
#include "vendors/stb_image/stb_image.h";
#source "vendors/stb_image/stb_image_impl.c";
#include "vendors/stb_image/stb_image_write.h";
#source "vendors/stb_image/stb_image_write_impl.c";
};