Skip to content
Browse files

fix compiler crash on syntax error, introduced in commit a9bb09d

  • Loading branch information...
1 parent 3676914 commit 94c41505ae6f258cb5b164a18fb903fbaee5c9b0 @kazuho kazuho committed Jun 4, 2012
Showing with 11 additions and 5 deletions.
  1. +5 −5 src/expression.js
  2. +6 −0 t/compile_error/116.map-property-is-not-number.jsx
View
10 src/expression.js
@@ -1320,16 +1320,16 @@ var ArrayExpression = exports.ArrayExpression = BinaryExpression.extend({
// obtain classDef
var expr1Type = this._expr1.getType().resolveIfMayBeUndefined();
if (expr1Type instanceof ObjectType) {
- return this._analyzeApplicationOnObject(expr1Type);
+ return this._analyzeApplicationOnObject(context, expr1Type);
} else if (expr1Type.equals(Type.variantType)) {
- return this._analyzeApplicationOnVariant();
+ return this._analyzeApplicationOnVariant(context);
return true;
}
context.errors.push(new CompileError(this._token, "cannot apply []; the operator is only applicable against an array or an variant"));
return false;
},
- _analyzeApplicationOnObject: function (expr1Type) {
+ _analyzeApplicationOnObject: function (context, expr1Type) {
var expr1ClassDef = expr1Type.getClassDef();
// obtain type of operator []
var accessorType = expr1ClassDef.getMemberTypeByName("__native_index_operator__", false, ClassDefinition.GET_MEMBER_MODE_ALL);
@@ -1347,15 +1347,15 @@ var ArrayExpression = exports.ArrayExpression = BinaryExpression.extend({
}
// check type of expr2
if (! this._expr2.getType().isConvertibleTo(accessorType.getArgumentTypes()[0])) {
- context.errors.push(new CompileError(this._token, "index type is incompatible (expected '" + accessorType.getArgumentTypes()[0].toString() + "', got '" + this._expr2.getType().toString() + "'"));
+ context.errors.push(new CompileError(this._token, "index type is incompatible (expected '" + accessorType.getArgumentTypes()[0].toString() + "', got '" + this._expr2.getType().toString() + "')"));
return false;
}
// set type of the expression
this._type = accessorType.getReturnType();
return true;
},
- _analyzeApplicationOnVariant: function () {
+ _analyzeApplicationOnVariant: function (context) {
var expr2Type = this._expr2.getType().resolveIfMayBeUndefined();
if (! (expr2Type.equals(Type.stringType) || expr2Type.isConvertibleTo(Type.numberType))) {
context.errors.push(new CompileError("the argument of variant[] should be a string or a number"));
View
6 t/compile_error/116.map-property-is-not-number.jsx
@@ -0,0 +1,6 @@
+class Test {
+ static function run() : void {
+ var m = { a: 1 };
+ m[0];
+ }
+}

0 comments on commit 94c4150

Please sign in to comment.
Something went wrong with that request. Please try again.