fix(0113): negated-literal global initializers fold as constants
globalInitValue had no unary_op arm, so g : s64 = -1; fell into the catch-all 'must be initialized by a compile-time constant' even though constExprValue already folds negate(literal) for the module-const identifier route. The new arm routes through constExprValue and applies the direct-literal rules to the folded value: checkIntLiteralFits on ints (g : s8 = -300 gets the range diagnostic), and a negated float at an integer global narrows only when integral (-4.0 folds to -4, -4.5 errors). Binary-op initializers keep the specific non-constant diagnostic. Regression: examples/0175-types-negative-literal-global.sx.
This commit is contained in:
16
examples/0175-types-negative-literal-global.sx
Normal file
16
examples/0175-types-negative-literal-global.sx
Normal file
@@ -0,0 +1,16 @@
|
||||
// A negated literal is a compile-time constant for a global initializer:
|
||||
// ints serialize directly, an integral negative float narrows into an
|
||||
// integer global (non-integral errors), and boundary values fit exactly.
|
||||
// Out-of-range negatives get the literal fits-check, not "non-constant".
|
||||
// Regression (issue 0113): `g : s64 = -1;` was rejected as not a
|
||||
// compile-time constant (globalInitValue had no unary_op arm).
|
||||
|
||||
#import "modules/std.sx";
|
||||
|
||||
g1 : s64 = -1;
|
||||
g2 : s64 = -4.0;
|
||||
g3 : s8 = -128;
|
||||
|
||||
main :: () {
|
||||
print("{} {} {}\n", g1, g2, g3);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
-1 -4 -128
|
||||
Reference in New Issue
Block a user