diff --git a/src/read.c b/src/read.c index b34e3c2377..968c8d4805 100644 --- a/src/read.c +++ b/src/read.c @@ -2050,7 +2050,9 @@ static void ReadFor(ScannerState * s, TypSymbolSet follow) Match(s, S_FOR, "for", follow); /* */ - ReadCallVarAss(s, follow, 'r'); + volatile LHSRef ref = ReadVar(s, follow); + if (ref.type != R_INVALID) + EvalRef(ref, 1); /* 'in' */ Match(s, S_IN, "in", S_DO|S_OD|follow); diff --git a/tst/testinstall/coder.tst b/tst/testinstall/coder.tst index b9bf6a0f11..f223d8a9af 100644 --- a/tst/testinstall/coder.tst +++ b/tst/testinstall/coder.tst @@ -300,5 +300,41 @@ gap> function() Unbind(l![fail]); end(); Error, PosObj Assignment: must be a positive small integer (not the\ value 'fail') +# +# weird corner cases in for loop index variables +# +gap> function() for + in [1,2,3] do od; end(); +Syntax error: Identifier expected in stream:1 +function() for + in [1,2,3] do od; end(); + ^ +gap> function() local x; for x[1] in [1,2,3] do od; end(); +Syntax error: in expected in stream:1 +function() local x; for x[1] in [1,2,3] do od; end(); + ^ +gap> function() local x; for x{[1]} in [1,2,3] do od; end(); +Syntax error: in expected in stream:1 +function() local x; for x{[1]} in [1,2,3] do od; end(); + ^ +gap> function() for IsHPCGAP in [1,2,3] do od; end(); +Error, Variable: 'IsHPCGAP' is constant +gap> function() for IsHPCGAP[1] in [1,2,3] do od; end(); +Syntax error: in expected in stream:1 +function() for IsHPCGAP[1] in [1,2,3] do od; end(); + ^ +gap> function() for IsHPCGAP{[1]} in [1,2,3] do od; end(); +Syntax error: in expected in stream:1 +function() for IsHPCGAP{[1]} in [1,2,3] do od; end(); + ^ +gap> function() for PrintObj in [1,2,3] do od; end(); +Error, Variable: 'PrintObj' is read only +gap> function() for PrintObj[1] in [1,2,3] do od; end(); +Syntax error: in expected in stream:1 +function() for PrintObj[1] in [1,2,3] do od; end(); + ^ +gap> function() for PrintObj{[1]} in [1,2,3] do od; end(); +Syntax error: in expected in stream:1 +function() for PrintObj{[1]} in [1,2,3] do od; end(); + ^ + # gap> STOP_TEST("coder.tst", 1); diff --git a/tst/testinstall/interpreter.tst b/tst/testinstall/interpreter.tst index 9feee7aba8..4e327b36f4 100644 --- a/tst/testinstall/interpreter.tst +++ b/tst/testinstall/interpreter.tst @@ -252,6 +252,42 @@ gap> Unbind(l![fail]); Error, PosObj Assignment: must be a positive small integer (not the\ value 'fail') +# +# weird corner cases in for loop index variables +# +gap> for + in [1,2,3] do od; +Syntax error: Identifier expected in stream:1 +for + in [1,2,3] do od; + ^ +gap> for x[1] in [1,2,3] do od; +Syntax error: in expected in stream:1 +for x[1] in [1,2,3] do od; + ^ +gap> for x{[1]} in [1,2,3] do od; +Syntax error: in expected in stream:1 +for x{[1]} in [1,2,3] do od; + ^ +gap> for IsHPCGAP in [1,2,3] do od; +Error, Variable: 'IsHPCGAP' is constant +gap> for IsHPCGAP[1] in [1,2,3] do od; +Syntax error: in expected in stream:1 +for IsHPCGAP[1] in [1,2,3] do od; + ^ +gap> for IsHPCGAP{[1]} in [1,2,3] do od; +Syntax error: in expected in stream:1 +for IsHPCGAP{[1]} in [1,2,3] do od; + ^ +gap> for PrintObj in [1,2,3] do od; +Error, Variable: 'PrintObj' is read only +gap> for PrintObj[1] in [1,2,3] do od; +Syntax error: in expected in stream:1 +for PrintObj[1] in [1,2,3] do od; + ^ +gap> for PrintObj{[1]} in [1,2,3] do od; +Syntax error: in expected in stream:1 +for PrintObj{[1]} in [1,2,3] do od; + ^ + # # gap> STOP_TEST("interpreter.tst", 1);