Importc codegen fix (#25511)

This fixes two issues with impotc'ed types.
1. Passing an importc'ed inherited object to where superclass is
expected emitted `v.Sup` previously. Now it emits `v`, similar to cpp
codegen.
2. Casting between different nim types that resolve to the same C type
previously was done like `*(T*)&v`, now it is just `v`.

(cherry picked from commit 937e647f4f)
This commit is contained in:
Yuriy Glukhov
2026-02-13 14:29:01 +02:00
committed by narimiran
parent c5455c1515
commit f10dda264c
2 changed files with 25 additions and 2 deletions

View File

@@ -56,3 +56,22 @@ proc main = # bug #24677
for NDEBUG in 0..2:
doAssert NDEBUG == NDEBUG
main()
block: # importc type inheritance
type
A {.inheritable, pure, bycopy, importc: "int".} = object
B {.importc: "int", bycopy.} = object of A
{.emit: """
int foo(int a) {
return 123;
}
""".}
proc foo(a: A): B {.importc, nodecl.}
var a: A
var b = foo(a)
doAssert(cast[cint](b) == 123)
var c = foo(b)
doAssert(cast[cint](c) == 123)