From fef0b5a3517686ccfbd78531d297ddf91de2a680 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Wed, 27 Aug 2025 12:23:04 +0200 Subject: [PATCH] fixes #25114 (#25124) (cherry picked from commit d472022a7701d4c3c807980cf805606f2cb26277) --- compiler/ast.nim | 5 +++-- compiler/treetab.nim | 17 +++++++++++------ compiler/vmdef.nim | 4 +++- compiler/vmgen.nim | 22 ++++++++++++++-------- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index 13f7890bcd..a77e393720 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -815,6 +815,7 @@ type # nodes are compared by structure! counter*: int data*: TNodePairSeq + ignoreTypes*: bool TObjectSeq* = seq[RootRef] TObjectSet* = object @@ -1637,8 +1638,8 @@ proc initObjectSet*(): TObjectSet = result = TObjectSet(counter: 0) newSeq(result.data, StartSize) -proc initNodeTable*(): TNodeTable = - result = TNodeTable(counter: 0) +proc initNodeTable*(ignoreTypes=false): TNodeTable = + result = TNodeTable(counter: 0, ignoreTypes: ignoreTypes) newSeq(result.data, StartSize) proc skipTypes*(t: PType, kinds: TTypeKinds; maxIters: int): PType = diff --git a/compiler/treetab.nim b/compiler/treetab.nim index 6685c4a899..1fd539f0f2 100644 --- a/compiler/treetab.nim +++ b/compiler/treetab.nim @@ -42,32 +42,37 @@ proc hashTree*(n: PNode): Hash = #echo "hashTree ", result #echo n -proc treesEquivalent(a, b: PNode): bool = +proc treesEquivalent(a, b: PNode; ignoreTypes: bool): bool = if a == b: result = true elif (a != nil) and (b != nil) and (a.kind == b.kind): case a.kind - of nkEmpty, nkNilLit, nkType: result = true + of nkEmpty: result = true of nkSym: result = a.sym.id == b.sym.id of nkIdent: result = a.ident.id == b.ident.id of nkCharLit..nkUInt64Lit: result = a.intVal == b.intVal - of nkFloatLit..nkFloat64Lit: result = a.floatVal == b.floatVal + of nkFloatLit..nkFloat64Lit: + result = cast[uint64](a.floatVal) == cast[uint64](b.floatVal) + #result = a.floatVal == b.floatVal of nkStrLit..nkTripleStrLit: result = a.strVal == b.strVal + of nkType, nkNilLit: + result = a.typ == b.typ else: if a.len == b.len: for i in 0..= 0: @@ -1549,8 +1556,7 @@ template cannotEval(c: PCtx; n: PNode) = if c.config.cmd == cmdCheck and c.config.m.errorOutputs != {}: # nim check command with no error outputs doesn't need to cascade here, # includes `tryConstExpr` case which should not continue generating code - localError(c.config, n.info, "cannot evaluate at compile time: " & - n.renderTree) + localError(c.config, n.info, "cannot evaluate at compile time: " & n.renderTree) c.cannotEval = true return globalError(c.config, n.info, "cannot evaluate at compile time: " & @@ -1888,7 +1894,7 @@ proc genCheckedObjAccess(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags) = c.freeTemp(objR) proc genArrAccess(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags) = - if n[0].typ == nil: + if n[0].typ == nil: globalError(c.config, n.info, "cannot access array with nil type") return