From 470d3177030e799b15f5b67016210892e8959c93 Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Sun, 18 Oct 2026 14:21:32 -0500 Subject: [PATCH] Keep class methods named kind and code direct in the compiler resolveInferredReturn turns a return statement into a runtime fence through a Record view with element writes (`mutable["kind"] = ...`). The class method census treats a literal element write as a possible write to every method of that name, so in the native compiler every method named `kind` or `code` became a dynamic callback: AstWireFile.kind, called for each AST node access, went through a property bag and a method value. Property writes go through the receiver check instead, and no class instance is assignable to Record, so those methods are called directly again. Output of the compiler is unchanged. --- .../src/frontend/lowering/function-returns.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/compiler/src/frontend/lowering/function-returns.ts b/packages/compiler/src/frontend/lowering/function-returns.ts index d3c5eb1ba..5ba63be26 100644 --- a/packages/compiler/src/frontend/lowering/function-returns.ts +++ b/packages/compiler/src/frontend/lowering/function-returns.ts @@ -429,11 +429,14 @@ export function resolveInferredReturn( if (ice.length > 0) lowerer.diags.push(...ice); lowerer.runtimeFences.push(...captured.filter((d) => d.code !== "SC9001")); const first = captured.find((d) => d.code !== "SC9001"); + // Property writes, not literal element writes: the class method + // census reads `x["kind"] = …` as a possible write to every method + // named `kind`, which would make those methods dynamic in native builds. const mutable = e.stmt as unknown as Record; - delete mutable["value"]; - mutable["kind"] = "runtimeFence"; - mutable["code"] = first?.code ?? "SC1090"; - mutable["message"] = first + delete mutable.value; + mutable.kind = "runtimeFence"; + mutable.code = first?.code ?? "SC1090"; + mutable.message = first ? `${first.message} [${first.code}]` : "this return value has no lowering onto the instance's settled return type [SC1090]"; }