fix #6108
This commit is contained in:
parent
765116d547
commit
70380882c5
2 changed files with 21 additions and 5 deletions
|
|
@ -1365,13 +1365,16 @@ proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode =
|
|||
if lhsIsResult:
|
||||
n.typ = enforceVoidContext
|
||||
if c.p.owner.kind != skMacro and resultTypeIsInferrable(lhs.sym.typ):
|
||||
if cmpTypes(c, lhs.typ, rhs.typ) == isGeneric:
|
||||
var rhsTyp = rhs.typ
|
||||
if rhsTyp.kind in tyUserTypeClasses and rhsTyp.isResolvedUserTypeClass:
|
||||
rhsTyp = rhsTyp.lastSon
|
||||
if cmpTypes(c, lhs.typ, rhsTyp) in {isGeneric, isEqual}:
|
||||
internalAssert c.p.resultSym != nil
|
||||
lhs.typ = rhs.typ
|
||||
c.p.resultSym.typ = rhs.typ
|
||||
c.p.owner.typ.sons[0] = rhs.typ
|
||||
lhs.typ = rhsTyp
|
||||
c.p.resultSym.typ = rhsTyp
|
||||
c.p.owner.typ.sons[0] = rhsTyp
|
||||
else:
|
||||
typeMismatch(n.info, lhs.typ, rhs.typ)
|
||||
typeMismatch(n.info, lhs.typ, rhsTyp)
|
||||
|
||||
n.sons[1] = fitNode(c, le, rhs, n.info)
|
||||
if not newDestructors:
|
||||
|
|
|
|||
13
tests/concepts/tcomparable.nim
Normal file
13
tests/concepts/tcomparable.nim
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
type
|
||||
Comparable = concept a
|
||||
(a < a) is bool
|
||||
|
||||
proc myMax(a, b: Comparable): Comparable =
|
||||
if a < b:
|
||||
return b
|
||||
else:
|
||||
return a
|
||||
|
||||
doAssert myMax(5, 10) == 10
|
||||
doAssert myMax(31.3, 1.23124) == 31.3
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue