mutable decl syntax change

This commit is contained in:
2026-08-05 21:19:41 +02:00
parent 88b94197c9
commit 081a3fd5df
74 changed files with 870 additions and 733 deletions
+5 -17
View File
@@ -5952,7 +5952,7 @@ infer_statements :: proc(
#partial switch statement.kind {
case .Declaration:
if statement.expr == ast.INVALID_EXPR {
// Value block (`x :: { ... yield v }` / `x T = { ... }`): register the
// Value block (`x :: { ... yield v }` / `x T := { ... }`): register the
// binding (its declared type when annotated, else left open) and walk
// the block body. The build pass resolves the yielded value's type
// independently value blocks don't join the demand fixpoint.
@@ -6026,7 +6026,7 @@ infer_statements :: proc(
continue
}
expected_assignment := types.INVALID
if statement.target != ast.INVALID_EXPR {
if statement.target != ast.INVALID_EXPR && !symbol.is_valid(statement.name) {
expected_assignment = infer_expr(checker, statement.target, locals^[:], pkg, file, demanded, local_types)
target_expr := checker.ast_module.exprs[statement.target]
if target_expr.kind == .Name && !symbol.is_valid(target_expr.qualifier) {
@@ -6055,7 +6055,7 @@ infer_statements :: proc(
// type onto open-constant operands and poison their family. Operands of an
// arithmetic RHS resolve from their own authoritative uses.
rhs_is_arith := is_arith_kind(checker.ast_module.exprs[statement.expr].kind)
if statement.target != ast.INVALID_EXPR {
if statement.target != ast.INVALID_EXPR && !symbol.is_valid(statement.name) {
target_type := expected_assignment
target_expr := checker.ast_module.exprs[statement.target]
if target_expr.kind == .Name && !symbol.is_valid(target_expr.qualifier) {
@@ -10922,7 +10922,7 @@ build_block :: proc(
}
switch statement.kind {
case .Declaration:
// A value block (`x :: { ... yield v }` / `x T = { ... }`): the parser
// A value block (`x :: { ... yield v }` / `x T := { ... }`): the parser
// leaves `expr` invalid and stashes the block in `body`. Build it, then
// declare the local from the yielded value (its type for an untyped `::`).
if statement.expr == ast.INVALID_EXPR {
@@ -11123,7 +11123,7 @@ build_block :: proc(
ctx.problematic^ = ctx.problematic^ || checker.module.exprs[value].kind == .Invalid
}
case .Assignment:
if statement.target != ast.INVALID_EXPR {
if statement.target != ast.INVALID_EXPR && !symbol.is_valid(statement.name) {
target_expr := build_expr(
checker, statement.target, ctx.locals^[:], ctx.global_reads, ctx.calls,
types.INVALID, ctx.pkg, ctx.file,
@@ -14349,18 +14349,6 @@ build_globals :: proc(checker: ^Checker) {
)
expr = invalid_hir_expr(checker, global.span, diagnostic)
}
if !global.immutable {
if !types.is_valid(global.type) {
diagnostic = source.addf(
checker.diagnostics,
global.span,
"mutable global '%s' requires a type annotation",
symbol_text(checker, global.name),
)
global_type = types.I64
expr = invalid_hir_expr(checker, global.span, diagnostic, global_type)
}
}
static_value, is_static := static_integer_value(&checker.module, expr)
is_static = is_static && diagnostic == source.INVALID_DIAGNOSTIC && global.immutable
_ = hir.global_id(len(checker.module.globals))