Skip to content

Commit

Permalink
just wanna try this
Browse files Browse the repository at this point in the history
  • Loading branch information
Graveflo committed Jul 24, 2024
1 parent 37ea900 commit 2db0ad3
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type

const
isNilConversion = isConvertible # maybe 'isIntConv' fits better?
maxInheritancePenalty = high(int) div 2

proc markUsed*(c: PContext; info: TLineInfo, s: PSym; checkStyle = true)
proc markOwnerModuleAsUsed*(c: PContext; s: PSym)
Expand Down Expand Up @@ -292,9 +293,9 @@ proc cmpInheritancePenalty(a, b: int): int =
var eb = b
var ea = a
if b < 0:
eb = 100 # defacto max penalty
eb = maxInheritancePenalty
if a < 0:
ea = 100
ea = maxInheritancePenalty
eb - ea

proc cmpCandidates*(a, b: TCandidate, isFormal=true): int =
Expand All @@ -308,7 +309,8 @@ proc cmpCandidates*(a, b: TCandidate, isFormal=true): int =
if result != 0: return
result = a.convMatches - b.convMatches
if result != 0: return
result = cmpInheritancePenalty(a.inheritancePenalty, b.inheritancePenalty)

result = b.inheritancePenalty - a.inheritancePenalty
if result != 0: return
if isFormal:
# check for generic subclass relation
Expand Down Expand Up @@ -1570,7 +1572,8 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
if aAsObject.kind == tyObject and trIsOutParam notin flags:
let baseType = aAsObject.base
if baseType != nil:
inc c.inheritancePenalty, 1 + int(c.inheritancePenalty < 0)
assert c.inheritancePenalty > -1
inc c.inheritancePenalty
let ret = typeRel(c, f, baseType, flags)
return if ret in {isEqual,isGeneric}: isSubtype else: ret

Expand Down Expand Up @@ -1667,7 +1670,8 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
depth = -1

if depth >= 0:
inc c.inheritancePenalty, depth + int(c.inheritancePenalty < 0)
assert c.inheritancePenalty > -1
inc c.inheritancePenalty, depth
# bug #4863: We still need to bind generic alias crap, so
# we cannot return immediately:
result = if depth == 0: isGeneric else: isSubtype
Expand Down

0 comments on commit 2db0ad3

Please sign in to comment.