diff options
Diffstat (limited to 'tests/tobjcov.nim')
-rwxr-xr-x | tests/tobjcov.nim | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/tobjcov.nim b/tests/tobjcov.nim new file mode 100755 index 000000000..da34fcb60 --- /dev/null +++ b/tests/tobjcov.nim @@ -0,0 +1,17 @@ +# Covariance is not type safe: + +type + TA = object + 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 Nimrod proc (x: TB) is compatible to proc (x: TA), +# but this is not type safe: +var f: proc (x: var TA) = bp +var a: TA +f(a) # bp expects a TB, but gets a TA + |