Skip to content

Commit

Permalink
Fixed error message in case of indexing an undeclared variable, closes
Browse files Browse the repository at this point in the history
  • Loading branch information
showstopper committed May 13, 2011
1 parent bb1b111 commit f579a94
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions source/rock/middle/ArrayAccess.ooc
Expand Up @@ -49,6 +49,12 @@ ArrayAccess: class extends Expression {
resolve: func (trail: Trail, res: Resolver) -> Response {

if(res fatal && type == null) {
if (array instanceOf?(VariableAccess)) {
if (!array isResolved()) {
res wholeAgain(this, "Reference to undeclared variable.")
return Response OK
}
}
res throwError(InvalidArrayAccess new(token, "Trying to index something that isn't an array, nor has an overload for the []/[]= operators"))
}

Expand Down Expand Up @@ -237,6 +243,7 @@ ArrayAccess: class extends Expression {

}

isResolved: func -> Bool { array isResolved() && type != null }
getScore: func (op: OperatorDecl, reqType: Type, assign: BinaryOp, res: Resolver) -> Int {

if(!(op getSymbol() equals?(assign != null ? "[]=" : "[]"))) {
Expand Down
8 changes: 8 additions & 0 deletions source/rock/middle/BinaryOp.ooc
Expand Up @@ -139,6 +139,14 @@ BinaryOp: class extends Expression {
}

if(type == OpType ass) {
if (!left isResolved()) {
res wholeAgain(this, "Can't resolve '%s'. (maybe you forgot to declare a variable?)" format(left toString()))
return Response OK
} elseif (!right isResolved()) {
res wholeAgain(this, "Can't resolve %s. (maybe you forgot to declare a variable?" format(left toString()))
return Response OK
}

if(left getType() == null || !left isResolved()) {
res wholeAgain(this, "left type is unresolved"); return Response OK
}
Expand Down

0 comments on commit f579a94

Please sign in to comment.