@@ -17,7 +17,9 @@ use crate::{
17
17
expr:: { HirExpression , HirIdent , HirMethodReference , ImplKind , TraitMethod } ,
18
18
stmt:: HirPattern ,
19
19
} ,
20
- node_interner:: { DefinitionId , DefinitionKind , ExprId , FuncId , GlobalId , TraitImplKind } ,
20
+ node_interner:: {
21
+ DefinitionId , DefinitionInfo , DefinitionKind , ExprId , FuncId , GlobalId , TraitImplKind ,
22
+ } ,
21
23
} ;
22
24
23
25
use super :: { Elaborator , ResolverMeta , path_resolution:: PathResolutionItem } ;
@@ -542,8 +544,10 @@ impl Elaborator<'_> {
542
544
543
545
let type_generics = item. map ( |item| self . resolve_item_turbofish ( item) ) . unwrap_or_default ( ) ;
544
546
545
- let definition_kind =
546
- self . interner . try_definition ( definition_id) . map ( |definition| definition. kind . clone ( ) ) ;
547
+ let definition = self . interner . try_definition ( definition_id) ;
548
+ let is_comptime_local = !self . in_comptime_context ( )
549
+ && definition. is_some_and ( DefinitionInfo :: is_comptime_local) ;
550
+ let definition_kind = definition. as_ref ( ) . map ( |definition| definition. kind . clone ( ) ) ;
547
551
548
552
let mut bindings = TypeBindings :: new ( ) ;
549
553
@@ -574,7 +578,23 @@ impl Elaborator<'_> {
574
578
let typ = self . type_check_variable_with_bindings ( expr, id, generics, bindings) ;
575
579
self . interner . push_expr_type ( id, typ. clone ( ) ) ;
576
580
577
- ( id, typ)
581
+ // If this variable it a comptime local variable, use its current value as the final expression
582
+ if is_comptime_local {
583
+ let mut interpreter = self . setup_interpreter ( ) ;
584
+ let value = interpreter. evaluate ( id) ;
585
+ // If the value is an error it means the variable already had an error, so don't report it here again
586
+ // (the error will make no sense, it will say that a non-comptime variable was referenced at runtime
587
+ // but that's not true)
588
+ if value. is_ok ( ) {
589
+ let ( id, typ) = self . inline_comptime_value ( value, location) ;
590
+ self . debug_comptime ( location, |interner| id. to_display_ast ( interner) . kind ) ;
591
+ ( id, typ)
592
+ } else {
593
+ ( id, typ)
594
+ }
595
+ } else {
596
+ ( id, typ)
597
+ }
578
598
}
579
599
580
600
/// Solve any generics that are part of the path before the function, for example:
0 commit comments