Skip to content

Commit 980727e

Browse files
committed
Disallow arbitrary operators in variable declaration
1 parent ea1d160 commit 980727e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

TestHScript.hx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ class TestHScript extends TestCase {
124124
assertScript("var f:(x:Int)->(Int, Int)->Int = (x:Int) -> (y:Int, z:Int) -> x + y + z; f(3)(1, 2)", 6, null, true);
125125
assertScript("var a = 10; var b = 5; a - -b", 15);
126126
assertScript("var a = 10; var b = 5; a - b / 2", 7.5);
127+
assertScript("var a; a", null);
128+
assertScript("var a, b = 5; if (a == null) a = 2; a + b;", 7);
127129
assertScript("false && xxx", false);
128130
assertScript("true || xxx", true);
129131
assertScript("[for( x in arr ) switch( x ) { case 1: 55; case 3: 66; default: 0; }].join(':')",'55:0:66',{ arr : [1,2,3] });
@@ -249,4 +251,4 @@ class TestHScript extends TestCase {
249251
#end
250252
}
251253

252-
}
254+
}

hscript/Parser.hx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,14 @@ class Parser {
601601
tk = token();
602602
}
603603
var e = null;
604-
if( Type.enumEq(tk,TOp("=")) )
605-
e = parseExpr();
606-
else
607-
push(tk);
604+
605+
switch (tk)
606+
{
607+
case TOp("="): e = parseExpr();
608+
case TComma | TSemicolon: push(tk);
609+
default: unexpected(tk);
610+
}
611+
608612
mk(EVar(ident,t,e),p1,(e == null) ? tokenMax : pmax(e));
609613
case "while":
610614
var econd = parseExpr();

0 commit comments

Comments
 (0)