mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-01 13:09:14 +00:00
fixes #25945 When `@[]` appears inside a nested `if` expression that also contains statements, the AST wraps it in `nkStmtListExpr` nodes. The empty container's `tyEmpty` element type was never resolved to a concrete type, causing the C codegen to ICE with "cannot map the empty seq type to a C type". Walk through nested statement-list/block expressions in `fitNodePostMatch` to find the innermost value node and propagate the formal type to empty containers.
90 lines
1.7 KiB
Nim
90 lines
1.7 KiB
Nim
discard """
|
|
targets: "c cpp"
|
|
"""
|
|
|
|
# bug #19094
|
|
type
|
|
X = object
|
|
filler: array[2048, int]
|
|
innerAddress: uint
|
|
|
|
proc initX(): X =
|
|
result.innerAddress = cast[uint](result.addr)
|
|
|
|
proc initXInPlace(x: var X) =
|
|
x.innerAddress = cast[uint](x.addr)
|
|
|
|
block: # NRVO1
|
|
var x = initX()
|
|
let innerAddress = x.innerAddress
|
|
let outerAddress = cast[uint](x.addr)
|
|
doAssert(innerAddress == outerAddress) # [OK]
|
|
|
|
block: # NRVO2
|
|
var x: X
|
|
initXInPlace(x)
|
|
let innerAddress = x.innerAddress
|
|
let outerAddress = cast[uint](x.addr)
|
|
doAssert(innerAddress == outerAddress) # [OK]
|
|
|
|
block: # bug #22354
|
|
type Object = object
|
|
foo: int
|
|
|
|
proc takeFoo(self: var Object): int =
|
|
result = self.foo
|
|
self.foo = 999
|
|
|
|
proc doSomething(self: var Object; foo: int = self.takeFoo()) =
|
|
discard
|
|
|
|
proc main() =
|
|
var obj = Object(foo: 2)
|
|
obj.doSomething()
|
|
doAssert obj.foo == 999
|
|
|
|
|
|
main()
|
|
|
|
proc main = # bug #24677
|
|
let NULL = 1
|
|
doAssert NULL == 1
|
|
|
|
var COMMA = 1
|
|
doAssert COMMA == 1
|
|
|
|
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)
|
|
|
|
block: # bug #25945
|
|
var stateRefund = 0
|
|
let authCode =
|
|
if true:
|
|
if false:
|
|
stateRefund += 0
|
|
@[]
|
|
else:
|
|
@([1.byte])
|
|
|
|
discard (if true: (discard; @[]) else: @[0])
|