Fix comparison of tyGenericBody in typerel (#8045)
As shown in #7734 and #7733 the logic in typerel fails to determine that `type Foo` and `type Foo` are indeed equal. Fixes #7734
This commit is contained in:
parent
73f9ce0221
commit
88714e77d8
2 changed files with 20 additions and 1 deletions
|
|
@ -1425,7 +1425,7 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
|
||||||
|
|
||||||
of tyGenericBody:
|
of tyGenericBody:
|
||||||
considerPreviousT:
|
considerPreviousT:
|
||||||
if a.kind == tyGenericInst and a.sons[0] == f:
|
if a == f or a.kind == tyGenericInst and a.sons[0] == f:
|
||||||
bindingRet isGeneric
|
bindingRet isGeneric
|
||||||
let ff = lastSon(f)
|
let ff = lastSon(f)
|
||||||
if ff != nil:
|
if ff != nil:
|
||||||
|
|
|
||||||
19
tests/typerel/t7734.nim
Normal file
19
tests/typerel/t7734.nim
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
type
|
||||||
|
Foo[T: SomeFloat] = object
|
||||||
|
learning_rate: T
|
||||||
|
|
||||||
|
Bar[T: SomeFloat] = object
|
||||||
|
learning_rate: T
|
||||||
|
momentum: T
|
||||||
|
|
||||||
|
Model = object
|
||||||
|
weight: int
|
||||||
|
|
||||||
|
FooClass = Foo or Bar
|
||||||
|
|
||||||
|
|
||||||
|
proc optimizer[M; T: SomeFloat](model: M, _: typedesc[Foo], learning_rate: T): Foo[T] =
|
||||||
|
result.learning_rate = learning_rate
|
||||||
|
|
||||||
|
let a = Model(weight: 1)
|
||||||
|
let opt = a.optimizer(Foo, 10.0)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue