Files
Nim/tests/objects/tobjcov.nim
Timothee Cour 7e1ae35195 testament: error instead of silently ignore invalid targets; remove pointless alias target vs targets; document matrix; DRY (#16343)
* testament: error instead of silently ignore invalid targets
* s/target/targets/
* fix test; refs #16344
* address comments
* Update testament/specs.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2020-12-14 10:58:29 +01:00

25 lines
640 B
Nim

discard """
action: compile
targets: "c"
"""
# Covariance is not type safe:
# Note: `nim cpp` makes it a compile error (after codegen), even with:
# `var f = cast[proc (x: var TA) {.nimcall.}](cast[pointer](bp))`, which
# currently removes all the `cast` in cgen'd code, hence the compile error.
type
TA = object of RootObj
a: int
TB = object of TA
b: array[0..5000_000, int]
proc ap(x: var TA) = x.a = -1
proc bp(x: var TB) = x.b[high(x.b)] = -1
# in Nim proc (x: TB) is compatible to proc (x: TA),
# but this is not type safe:
var f = cast[proc (x: var TA) {.nimcall.}](bp)
var a: TA
f(a) # bp expects a TB, but gets a TA