Closed arkanoid87 closed 8 months ago
It's probably a bug in the compiler regarding old style concepts. The type definition is the issue. The compiler seems to bind the Length
in the Foo
definition to the same symbols. The following variant:
import unchained
type Foo[DA, DB] = object
a: DA
b: DB
proc initFoo[DA: Length, DB: Length](a: DA, b: DB): Foo[DA, DB] =
Foo[DA, DB](a: a, b: b)
echo initFoo(1.m, 2.m) # compiles correctly
echo initFoo(1.m, 2.cm) # got: <typedesc[Meter], typedesc[CentiMeter]> but expected: <DA: Length, DB: Length>
works fine.
Feel free to report it as a Nim issue. This code here reproduces the same problem:
type
cm = distinct float
m = distinct float
Length = concept x
x.float is float
type Foo[DA: Length, DB: Length] = object
a: DA
b: DB
proc initFoo[DA: Length, DB: Length](a: DA, b: DB): Foo[DA, DB] =
Foo[DA, DB](a: a, b: b)
echo initFoo(1.m, 2.m) # compiles correctly
echo initFoo(1.m, 2.cm) # got: <typedesc[Meter], typedesc[CentiMeter]> but expected: <DA: Length, DB: Length>
Thanks a lot for the quick and complete response.
here we go https://github.com/nim-lang/Nim/issues/23405
I've tried a couple of other quantities, and I got same error, but can't say if it happens for all quantities.