proc redefinition search based on the type system instead of on sloppy AST matching
This will work the same for procs/templates/macros/etc, having arbitrary mix of implicit and explicit generics (as long as the symbols are equivalent for the purposes of overload resolution, they will be detected as redefinitions) fixes tgeneric
This commit is contained in:
parent
fa3bb8d66b
commit
e3f53409f6
3 changed files with 48 additions and 30 deletions
|
|
@ -606,8 +606,10 @@ type
|
|||
|
||||
TTypeCmpFlag* = enum
|
||||
IgnoreTupleFields
|
||||
IgnoreCC
|
||||
ExactTypeDescValues
|
||||
ExactGenericParams
|
||||
ExactConstraints
|
||||
AllowCommonBase
|
||||
|
||||
TTypeCmpFlags* = set[TTypeCmpFlag]
|
||||
|
|
@ -637,15 +639,17 @@ proc sameTypeOrNilAux(a, b: PType, c: var TSameTypeClosure): bool =
|
|||
if a == nil or b == nil: result = false
|
||||
else: result = sameTypeAux(a, b, c)
|
||||
|
||||
proc sameType*(a, b: PType, flags: TTypeCmpFlags = {}): bool =
|
||||
var c = initSameTypeClosure()
|
||||
c.flags = flags
|
||||
result = sameTypeAux(a, b, c)
|
||||
|
||||
proc sameTypeOrNil*(a, b: PType, flags: TTypeCmpFlags = {}): bool =
|
||||
if a == b:
|
||||
result = true
|
||||
else:
|
||||
else:
|
||||
if a == nil or b == nil: result = false
|
||||
else:
|
||||
var c = initSameTypeClosure()
|
||||
c.flags = flags
|
||||
result = sameTypeAux(a, b, c)
|
||||
else: result = sameType(a, b, flags)
|
||||
|
||||
proc equalParam(a, b: PSym): TParamsEquality =
|
||||
if sameTypeOrNil(a.typ, b.typ, {ExactTypeDescValues}) and
|
||||
|
|
@ -661,7 +665,15 @@ proc equalParam(a, b: PSym): TParamsEquality =
|
|||
result = paramsIncompatible
|
||||
else:
|
||||
result = paramsNotEqual
|
||||
|
||||
|
||||
proc sameConstraints(a, b: PNode): bool =
|
||||
internalAssert a.len == b.len
|
||||
for i in 1 .. <a.len:
|
||||
if not exprStructuralEquivalent(a[i].sym.constraint,
|
||||
b[i].sym.constraint):
|
||||
return false
|
||||
return true
|
||||
|
||||
proc equalParams(a, b: PNode): TParamsEquality =
|
||||
result = paramsEqual
|
||||
var length = sonsLen(a)
|
||||
|
|
@ -860,8 +872,9 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
|
|||
else:
|
||||
result = sameFlags(a, b)
|
||||
of tyGenericParam:
|
||||
result = if ExactGenericParams in c.flags: a.id == b.id
|
||||
else: sameChildrenAux(a, b, c) and sameFlags(a, b)
|
||||
result = sameChildrenAux(a, b, c) and sameFlags(a, b)
|
||||
if result and ExactGenericParams in c.flags:
|
||||
result = a.sym.position == b.sym.position
|
||||
of tyGenericInvokation, tyGenericBody, tySequence,
|
||||
tyOpenArray, tySet, tyRef, tyPtr, tyVar, tyArrayConstr,
|
||||
tyArray, tyProc, tyConst, tyMutable, tyVarargs, tyIter,
|
||||
|
|
@ -869,7 +882,8 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
|
|||
cycleCheck()
|
||||
result = sameChildrenAux(a, b, c) and sameFlags(a, b)
|
||||
if result and a.kind == tyProc:
|
||||
result = a.callConv == b.callConv
|
||||
result = ((IgnoreCC in c.flags) or a.callConv == b.callConv) and
|
||||
((ExactConstraints notin c.flags) or sameConstraints(a.n, b.n))
|
||||
of tyRange:
|
||||
cycleCheck()
|
||||
result = sameTypeOrNilAux(a.sons[0], b.sons[0], c) and
|
||||
|
|
@ -877,10 +891,6 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
|
|||
sameValue(a.n.sons[1], b.n.sons[1])
|
||||
of tyNone: result = false
|
||||
|
||||
proc sameType*(x, y: PType): bool =
|
||||
var c = initSameTypeClosure()
|
||||
result = sameTypeAux(x, y, c)
|
||||
|
||||
proc sameBackendType*(x, y: PType): bool =
|
||||
var c = initSameTypeClosure()
|
||||
c.flags.incl IgnoreTupleFields
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue