Simple Errors beyond Syntax
Some kinds or errors we can check using straightforward checks:
a class is defined more than once
class A { …} class B { … } class A { … }
a variable is defined more than once:
int x; int y; int x;
a class member is overloaded (forbidden in
Tool, requires
override keyword in Scala):
class A { int x; … } class B extends A { int x; … }
a method is overloaded (forbidden in
Tool, requires
override keyword in Scala):
class A { int x; … } class B extends A { int x; … }
a method argument is shadowed by a local variable declaration (forbidden in Java, Tool):
def (x:Int) { var x : Int; …}
two method arguments have the same name:
def (x:Int,y:Int,x:Int) { … }
a class name is used as a symbol (as parent class or type, for instance) but is not declared:
class A extends Objekt {}
an identifier is used as a variable but is not declared:
def(amount:Int) { total = total + ammount }
the inheritance graph has a cycle:
class A extends B {} class B extends C {} class C extends A
To make it efficient and clean to check for such errors, we associate mapping from each identifier to the symbol that the identifier represents.
We use Map data structures to maintain this mapping.
The rules that specify how declarations are used to construct such maps are given by scope rules of the programming language.