[refactoring] don't use 'defer'
This commit is contained in:
parent
1acb9bae94
commit
210988c532
1 changed files with 18 additions and 13 deletions
|
|
@ -2296,7 +2296,8 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||||
arg: PNode # current prepared argument
|
arg: PNode # current prepared argument
|
||||||
formal: PSym # current routine parameter
|
formal: PSym # current routine parameter
|
||||||
|
|
||||||
defer:
|
template noMatch() =
|
||||||
|
m.state = csNoMatch
|
||||||
m.firstMismatch.arg = a
|
m.firstMismatch.arg = a
|
||||||
m.firstMismatch.formal = formal
|
m.firstMismatch.formal = formal
|
||||||
|
|
||||||
|
|
@ -2306,19 +2307,19 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||||
# better match over other routines with no such restriction:
|
# better match over other routines with no such restriction:
|
||||||
inc(m.genericMatches, 100)
|
inc(m.genericMatches, 100)
|
||||||
else:
|
else:
|
||||||
m.state = csNoMatch
|
noMatch()
|
||||||
return
|
return
|
||||||
|
|
||||||
if formal.typ.kind == tyVar:
|
if formal.typ.kind == tyVar:
|
||||||
let argConverter = if arg.kind == nkHiddenDeref: arg[0] else: arg
|
let argConverter = if arg.kind == nkHiddenDeref: arg[0] else: arg
|
||||||
if argConverter.kind == nkHiddenCallConv:
|
if argConverter.kind == nkHiddenCallConv:
|
||||||
if argConverter.typ.kind != tyVar:
|
if argConverter.typ.kind != tyVar:
|
||||||
m.state = csNoMatch
|
|
||||||
m.firstMismatch.kind = kVarNeeded
|
m.firstMismatch.kind = kVarNeeded
|
||||||
|
noMatch()
|
||||||
return
|
return
|
||||||
elif not n.isLValue:
|
elif not n.isLValue:
|
||||||
m.state = csNoMatch
|
|
||||||
m.firstMismatch.kind = kVarNeeded
|
m.firstMismatch.kind = kVarNeeded
|
||||||
|
noMatch()
|
||||||
return
|
return
|
||||||
|
|
||||||
m.state = csMatch # until proven otherwise
|
m.state = csMatch # until proven otherwise
|
||||||
|
|
@ -2354,12 +2355,12 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||||
prepareNamedParam(n.sons[a], c)
|
prepareNamedParam(n.sons[a], c)
|
||||||
if n.sons[a].sons[0].kind != nkIdent:
|
if n.sons[a].sons[0].kind != nkIdent:
|
||||||
localError(c.config, n.sons[a].info, "named parameter has to be an identifier")
|
localError(c.config, n.sons[a].info, "named parameter has to be an identifier")
|
||||||
m.state = csNoMatch
|
noMatch()
|
||||||
return
|
return
|
||||||
formal = getSymFromList(m.callee.n, n.sons[a].sons[0].ident, 1)
|
formal = getSymFromList(m.callee.n, n.sons[a].sons[0].ident, 1)
|
||||||
if formal == nil:
|
if formal == nil:
|
||||||
# no error message!
|
# no error message!
|
||||||
m.state = csNoMatch
|
noMatch()
|
||||||
return
|
return
|
||||||
if containsOrIncl(marker, formal.position):
|
if containsOrIncl(marker, formal.position):
|
||||||
m.firstMismatch.kind = kAlreadyGiven
|
m.firstMismatch.kind = kAlreadyGiven
|
||||||
|
|
@ -2368,7 +2369,7 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||||
# bug #3836 of why that is not sound (other overload with
|
# bug #3836 of why that is not sound (other overload with
|
||||||
# different parameter names could match later on):
|
# different parameter names could match later on):
|
||||||
when false: localError(n.sons[a].info, errCannotBindXTwice, formal.name.s)
|
when false: localError(n.sons[a].info, errCannotBindXTwice, formal.name.s)
|
||||||
m.state = csNoMatch
|
noMatch()
|
||||||
return
|
return
|
||||||
m.baseTypeMatch = false
|
m.baseTypeMatch = false
|
||||||
m.typedescMatched = false
|
m.typedescMatched = false
|
||||||
|
|
@ -2378,7 +2379,7 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||||
n.sons[a].sons[1], n.sons[a].sons[1])
|
n.sons[a].sons[1], n.sons[a].sons[1])
|
||||||
m.firstMismatch.kind = kTypeMismatch
|
m.firstMismatch.kind = kTypeMismatch
|
||||||
if arg == nil:
|
if arg == nil:
|
||||||
m.state = csNoMatch
|
noMatch()
|
||||||
return
|
return
|
||||||
checkConstraint(n.sons[a].sons[1])
|
checkConstraint(n.sons[a].sons[1])
|
||||||
if m.baseTypeMatch:
|
if m.baseTypeMatch:
|
||||||
|
|
@ -2419,15 +2420,16 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||||
incrIndexType(container.typ)
|
incrIndexType(container.typ)
|
||||||
checkConstraint(n.sons[a])
|
checkConstraint(n.sons[a])
|
||||||
else:
|
else:
|
||||||
m.state = csNoMatch
|
noMatch()
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
m.firstMismatch.kind = kExtraArg
|
m.firstMismatch.kind = kExtraArg
|
||||||
m.state = csNoMatch
|
noMatch()
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if m.callee.n.sons[f].kind != nkSym:
|
if m.callee.n.sons[f].kind != nkSym:
|
||||||
internalError(c.config, n.sons[a].info, "matches")
|
internalError(c.config, n.sons[a].info, "matches")
|
||||||
|
noMatch()
|
||||||
return
|
return
|
||||||
formal = m.callee.n.sons[f].sym
|
formal = m.callee.n.sons[f].sym
|
||||||
m.firstMismatch.kind = kTypeMismatch
|
m.firstMismatch.kind = kTypeMismatch
|
||||||
|
|
@ -2435,7 +2437,7 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||||
m.firstMismatch.kind = kAlreadyGiven
|
m.firstMismatch.kind = kAlreadyGiven
|
||||||
# already in namedParams: (see above remark)
|
# already in namedParams: (see above remark)
|
||||||
when false: localError(n.sons[a].info, errCannotBindXTwice, formal.name.s)
|
when false: localError(n.sons[a].info, errCannotBindXTwice, formal.name.s)
|
||||||
m.state = csNoMatch
|
noMatch()
|
||||||
return
|
return
|
||||||
|
|
||||||
if formal.typ.isVarargsUntyped:
|
if formal.typ.isVarargsUntyped:
|
||||||
|
|
@ -2452,7 +2454,7 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||||
arg = paramTypesMatch(m, formal.typ, n.sons[a].typ,
|
arg = paramTypesMatch(m, formal.typ, n.sons[a].typ,
|
||||||
n.sons[a], nOrig.sons[a])
|
n.sons[a], nOrig.sons[a])
|
||||||
if arg == nil:
|
if arg == nil:
|
||||||
m.state = csNoMatch
|
noMatch()
|
||||||
return
|
return
|
||||||
if m.baseTypeMatch:
|
if m.baseTypeMatch:
|
||||||
assert formal.typ.kind == tyVarargs
|
assert formal.typ.kind == tyVarargs
|
||||||
|
|
@ -2481,10 +2483,13 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||||
# this assertion can be off
|
# this assertion can be off
|
||||||
localError(c.config, n.sons[a].info, "cannot convert $1 to $2" % [
|
localError(c.config, n.sons[a].info, "cannot convert $1 to $2" % [
|
||||||
typeToString(n.sons[a].typ), typeToString(formal.typ) ])
|
typeToString(n.sons[a].typ), typeToString(formal.typ) ])
|
||||||
m.state = csNoMatch
|
noMatch()
|
||||||
return
|
return
|
||||||
checkConstraint(n.sons[a])
|
checkConstraint(n.sons[a])
|
||||||
inc(a)
|
inc(a)
|
||||||
|
# for some edge cases (see tdont_return_unowned_from_owned test case)
|
||||||
|
m.firstMismatch.arg = a
|
||||||
|
m.firstMismatch.formal = formal
|
||||||
|
|
||||||
proc semFinishOperands*(c: PContext, n: PNode) =
|
proc semFinishOperands*(c: PContext, n: PNode) =
|
||||||
# this needs to be called to ensure that after overloading resolution every
|
# this needs to be called to ensure that after overloading resolution every
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue