@@ -4890,16 +4890,6 @@ struct Typechecker {
48904890 }
48914891 }
48924892 scope.comptime_bindings[type_name] = value
4893- let checked_var = CheckedVariable(
4894- name: type_name
4895- type_id: value.impl.type_id(&mut .program)
4896- is_mutable: false
4897- definition_span: value.span
4898- type_span: None
4899- visibility: CheckedVisibility::Public
4900- invisible_to_ide: false
4901- )
4902- scope.vars[type_name] = module.add_variable(checked_var)
49034893 }
49044894
49054895 if dependent_scope_id.has_value() {
@@ -9245,13 +9235,44 @@ struct Typechecker {
92459235
92469236 yield CheckedExpression::OptionalSome(expr: checked_expr, span, type_id: optional_type_id)
92479237 }
9248- Var(name, span) => {
9249- let var = .find_var_in_scope(scope_id, var: name)
9250- let result = match var {
9251- Some(var_) => CheckedExpression::Var(var: var_, span)
9238+ Var(name, span) => match .find_var_in_scope(scope_id, var: name) {
9239+ Some(var) => {
9240+ let var = .find_var_in_scope(scope_id, var: name)
9241+ let result = match var {
9242+ Some(var_) => CheckedExpression::Var(var: var_, span)
9243+ None => {
9244+ .error(format("Variable '{}' not found", name), span)
9245+
9246+ mut type_id: TypeId? = None
9247+ if type_hint.has_value() {
9248+ type_id = type_hint!.type_id
9249+ }
9250+
9251+ yield CheckedExpression::Var(
9252+ var: CheckedVariable(
9253+ name,
9254+ type_id: type_id.value_or(unknown_type_id()),
9255+ is_mutable: false,
9256+ definition_span: span,
9257+ type_span: None
9258+ visibility: CheckedVisibility::Public
9259+ invisible_to_ide: false
9260+ ),
9261+ span
9262+ )
9263+ }
9264+ }
9265+
9266+ if type_hint is Some(hint) and hint is MustBe(type_id) {
9267+ .unify_with_type(found_type: result.type(), expected_type: type_id, span)
9268+ }
9269+
9270+ yield result
9271+ }
9272+ None => match .find_comptime_binding_in_scope(scope_id, name) {
9273+ Some(value) => value_to_checked_expression(value, interpreter: .interpreter())
92529274 None => {
92539275 .error(format("Variable '{}' not found", name), span)
9254-
92559276 mut type_id: TypeId? = None
92569277 if type_hint.has_value() {
92579278 type_id = type_hint!.type_id
@@ -9271,12 +9292,6 @@ struct Typechecker {
92719292 )
92729293 }
92739294 }
9274-
9275- if type_hint is Some(hint) and hint is MustBe(type_id) {
9276- .unify_with_type(found_type: result.type(), expected_type: type_id, span)
9277- }
9278-
9279- yield result
92809295 }
92819296 ForcedUnwrap(expr, span) => {
92829297 let checked_expr = .typecheck_expression_and_dereference_if_needed(expr, scope_id, safety_mode, type_hint: None, span)
0 commit comments