From 52809cd3dd43baecde82a251a83ebf6e87a16bb3 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 28 Nov 2024 00:36:57 +0800 Subject: [PATCH] fixes #24476; remove proc type cast if they are same types for backends (#24480) fixes #24476 closes https://github.com/nim-lang/Nim/pull/24479 (cherry picked from commit 5340005869d513e5c6af06e5d963bcb77abb3fa3) --- compiler/ccgexprs.nim | 2 ++ compiler/vtables.nim | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index c1ffdef576..90ea3513a1 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -2159,6 +2159,8 @@ proc genSomeCast(p: BProc, e: PNode, d: var TLoc) = [getTypeDesc(p.module, e.typ), rdCharLoc(a)], a.storage) elif etyp.kind == tyBool and srcTyp.kind in IntegralTypes: putIntoDest(p, d, e, "(($1) != 0)" % [rdCharLoc(a)], a.storage) + elif etyp.kind == tyProc and srcTyp.kind == tyProc and sameBackendType(etyp, srcTyp): + expr(p, e[1], d) else: if etyp.kind == tyPtr: # generates the definition of structs for casts like cast[ptr object](addr x)[] diff --git a/compiler/vtables.nim b/compiler/vtables.nim index 6d481fbb3c..b9c64ef687 100644 --- a/compiler/vtables.nim +++ b/compiler/vtables.nim @@ -15,7 +15,6 @@ proc dispatch(x: Base, params: ...) = var disp = newNodeI(nkIfStmt, base.info) - var vTableAccess = newNodeIT(nkBracketExpr, base.info, base.typ) let nimGetVTableSym = getCompilerProc(g, "nimGetVTable") let ptrPNimType = nimGetVTableSym.typ.n[1].sym.typ @@ -33,7 +32,7 @@ proc dispatch(x: Base, params: ...) = dispatchObject, newIntNode(nkIntLit, index) ) - getVTableCall.typ() = base.typ + getVTableCall.typ() = getSysType(g, unknownLineInfo, tyPointer) var vTableCall = newNodeIT(nkCall, base.info, base.typ.returnType) var castNode = newTree(nkCast, newNodeIT(nkType, base.info, base.typ),