1
1
use rue_parser:: { AstNode , ConstItem } ;
2
2
3
- use crate :: {
4
- compiler:: Compiler ,
5
- hir:: Hir ,
6
- symbol:: { Const , Symbol } ,
7
- SymbolId ,
8
- } ;
3
+ use crate :: { compiler:: Compiler , hir:: Hir , symbol:: Symbol , value:: Value , SymbolId } ;
9
4
10
5
impl Compiler < ' _ > {
11
6
/// Define a constant in the current scope, but don't lower its body.
@@ -21,9 +16,9 @@ impl Compiler<'_> {
21
16
let hir_id = self . db . alloc_hir ( Hir :: Unknown ) ;
22
17
23
18
if const_item. inline ( ) . is_some ( ) {
24
- * self . db . symbol_mut ( symbol_id) = Symbol :: InlineConst ( Const { type_id , hir_id } ) ;
19
+ * self . db . symbol_mut ( symbol_id) = Symbol :: InlineConst ( Value :: new ( hir_id , type_id ) ) ;
25
20
} else {
26
- * self . db . symbol_mut ( symbol_id) = Symbol :: Const ( Const { type_id , hir_id } ) ;
21
+ * self . db . symbol_mut ( symbol_id) = Symbol :: Const ( Value :: new ( hir_id , type_id ) ) ;
27
22
}
28
23
29
24
if let Some ( name) = const_item. name ( ) {
@@ -40,24 +35,25 @@ impl Compiler<'_> {
40
35
return ;
41
36
} ;
42
37
43
- let ( Symbol :: Const ( Const { type_id, .. } ) | Symbol :: InlineConst ( Const { type_id, .. } ) ) =
38
+ let ( Symbol :: Const ( Value { type_id, .. } ) | Symbol :: InlineConst ( Value { type_id, .. } ) ) =
44
39
self . db . symbol ( symbol_id) . clone ( )
45
40
else {
46
41
unreachable ! ( ) ;
47
42
} ;
48
43
49
- let output = self . compile_expr ( & expr, Some ( type_id) ) ;
44
+ let mut value = self . compile_expr ( & expr, Some ( type_id) ) ;
50
45
51
46
// Ensure that the expression is assignable to the constant's type.
52
- self . type_check ( output. type_id , type_id, const_item. syntax ( ) . text_range ( ) ) ;
47
+ self . type_check ( value. type_id , type_id, const_item. syntax ( ) . text_range ( ) ) ;
48
+ value. type_id = type_id;
53
49
54
50
// We ignore type guards here for now.
55
51
// Just set the constant HIR.
56
- let ( Symbol :: Const ( Const { hir_id , .. } ) | Symbol :: InlineConst ( Const { hir_id , .. } ) ) =
52
+ let ( Symbol :: Const ( symbol_value ) | Symbol :: InlineConst ( symbol_value ) ) =
57
53
self . db . symbol_mut ( symbol_id)
58
54
else {
59
55
unreachable ! ( ) ;
60
56
} ;
61
- * hir_id = output . hir_id ;
57
+ * symbol_value = value ;
62
58
}
63
59
}
0 commit comments