Skip to content

Commit 094caef

Browse files
Resolve const declaration as interned value if possible
1 parent f884ccf commit 094caef

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/analysis.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,12 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, options: ResolveOptions) Error
20022002
fallback_type = .unknown_type;
20032003
break :blk;
20042004
}
2005+
if (mut_token_tag == .keyword_const) num: {
2006+
const init_node = var_decl.ast.init_node.unwrap() orelse break :num;
2007+
const ip_ty = decl_type.ipIndex() orelse break :num;
2008+
const ip_index = try analyser.resolveCoercedIPValue(ip_ty, .of(init_node, handle)) orelse break :num;
2009+
return Type.fromIP(analyser, analyser.ip.typeOf(ip_index), ip_index);
2010+
}
20052011
return try decl_type.instanceTypeVal(analyser);
20062012
}
20072013

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))

tests/lsp_features/hover.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ test "alias with different type" {
10971097
\\const bar<cursor>: ?i32 = foo;
10981098
,
10991099
\\const foo: i32 = 1
1100-
\\(?i32)
1100+
\\(?i32 = 1)
11011101
, .{ .markup_kind = .plaintext });
11021102
}
11031103

0 commit comments

Comments
 (0)