Open
Description
Example
type
Either[T, U] = object of RootObj
t: T
u: U
E = object of Either[float, string]
proc test(T: typedesc, e: Either[T, T]) =
echo "matched ", typeof(e)
echo e
proc test1[T](e: Either[T, auto]) =
echo "matched ", typeof(e)
echo e
proc test2[T](e: Either[T, T]) =
echo "matched ", typeof(e)
echo e
proc makeE(): E =
result.t = -1.0
result.u = "string"
test(int, makeE())
test1[int](makeE())
when false:
discard "This doesn't compile as expected"
test2[int](makeE())
Current Output
matched Either[system.int, system.int]
(t: -4616189618054758400, u: 140610450096208)
matched Either[system.int, system.string]
(t: -4616189618054758400, u: "string")
Expected Output
This should not compile at all
Additional Information
$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-09-12
Copyright (c) 2006-2021 by Andreas Rumpf
git hash: 5d1608c9764416e74b36f6a772f16a66d58ddc28
active boot switches: -d:release -d:nimUseLinenoise