From b2bab45e23795f13bf764cdd1bbc0cf566ed7cd6 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 13 Aug 2026 22:08:24 +0800 Subject: [PATCH] fixes #26104; prevent compile-time-only `typeof` from being treated as a runtime alias --- 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..19c06c20d6 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.containsCompileTimeOnly) + 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..