Skip to content

Commit

Permalink
Catch overlap between class parameters and methods
Browse files Browse the repository at this point in the history
While identifier resolution already caught conflicts between class
parameters and inherited methods, it didn't do the same for methods
declared locally. This commit adds the same check and suggestion for
locally-declared methods as well.
  • Loading branch information
mwh committed Jun 5, 2014
1 parent a02263b commit 7da92e1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions identifierresolution.grace
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ method resolveIdentifiers(topNode) {
classScope.add(node.constructor.value)
classScope.bindAs(node.name.value)
pushScope
def paramScope = scope
if (false != node.generics) then {
for (node.generics) do {g->
scope.add(g.value) as "def"
Expand Down Expand Up @@ -634,6 +635,22 @@ method resolveIdentifiers(topNode) {
}
}
}
for (node.signature) do {s->
for (s.params) do {p->
if (scope.elements.contains(p.value)) then {
def suggestion = errormessages.suggestion.new
suggestion.insert("'")atPosition(p.linePos + p.value.size)onLine(p.line)
var primes := "'"
while { scope.elements.contains(p.value ++ primes) || paramScope.elements.contains(p.value ++ primes) } do {
suggestion.insert("'")atPosition(p.linePos + p.value.size)onLine(p.line)
primes := primes ++ "'"
}
errormessages.syntaxError("The parameter name '{p.value}' cannot be used because this class declares something named '{p.value}'.")atRange(
p.line, p.linePos, p.linePos + p.value.size - 1)withSuggestion(suggestion)

}
}
}
}
if (node.kind == "object") then {
pushScope
Expand Down

0 comments on commit 7da92e1

Please sign in to comment.