From cbb3b065c718ea7a7608ca614052634172599e8a Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Fri, 14 Aug 2026 19:36:55 +0800 Subject: [PATCH] =?UTF-8?q?fixes=20#26104;=20prevent=20compile-time-only?= =?UTF-8?q?=20`typeof`=20from=20being=20treated=20a=E2=80=A6=20(#26105)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …s a runtime alias fixes #26104 Follows up https://github.com/nim-lang/Nim/pull/25994 --- compiler/aliases.nim | 13 +++++++++++++ tests/ccgbugs/t26104.nim | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/ccgbugs/t26104.nim diff --git a/compiler/aliases.nim b/compiler/aliases.nim index 6877028c3a..639367b9b6 100644 --- a/compiler/aliases.nim +++ b/compiler/aliases.nim @@ -25,6 +25,11 @@ type pfStructural ## use structural prefix-chain detection and tree-walk pfBidirectional ## also check reverse direction per field in nkObjConstr +proc isCompileTimeOnlyNode(n: PNode): bool {.inline.} = + ## `typeof` and typedesc/static values describe types at compile time; they + ## do not read the runtime location that alias analysis is protecting. + n.kind == nkTypeOfExpr or (n.typ != nil and n.typ.isCompileTimeOnly) + func sameLocation(a, b: PNode): bool = template sameConstIndex(a, b: PNode): bool = a.kind in nkLiterals and b.kind in nkLiterals and a.intVal == b.intVal @@ -157,6 +162,9 @@ proc isPartOf*(a, b: PNode; flags: set[PartFlag] = {}): TAnalysisResult = ## ## x[] ?<| y depending on type ## ``` + if a.isCompileTimeOnlyNode or b.isCompileTimeOnlyNode: + return arNo + if a.kind == b.kind: case a.kind of nkSym: @@ -271,6 +279,11 @@ proc isPartOf*(a, b: PNode; flags: set[PartFlag] = {}): TAnalysisResult = of nkCallKinds: result = arNo for i in 1..