Skip to content

Commit 91d6cca

Browse files
Resolve const declaration as interned value if possible
1 parent 418a1f8 commit 91d6cca

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/analysis.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,12 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, options: ResolveOptions) Error
19051905
fallback_type = decl_type;
19061906
break :blk;
19071907
}
1908+
if (mut_token_tag == .keyword_const) num: {
1909+
const init_node = var_decl.ast.init_node.unwrap() orelse break :num;
1910+
const ip_ty = decl_type.ipIndex() orelse break :num;
1911+
const ip_index = try analyser.resolveCoercedIPValue(ip_ty, .of(init_node, handle)) orelse break :num;
1912+
return Type.fromIP(analyser, analyser.ip.typeOf(ip_index), ip_index);
1913+
}
19081914
return try decl_type.instanceTypeVal(analyser);
19091915
}
19101916

tests/analysis/integer_literal.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const bit_not_one = ~1;
3232
// ^^^^^^^^^^^ (comptime_int)((unknown value))
3333

3434
const const_u8: u8 = 42;
35-
// ^^^^^^^^ (u8)((unknown value)) TODO this should be `42`
35+
// ^^^^^^^^ (u8)(42)
3636

3737
var var_u8: u8 = 42;
3838
// ^^^^^^ (u8)((unknown value))

0 commit comments

Comments
 (0)