Allow lists to contain void elements if not optimizing and not lazy

LSO allows this. The compiler does too, but it chokes in RAIL.

This affected a test, which has been adjusted too.

Untyped lazy list elements can no longer be used in isolation in expression lists (including FOR initializator and iterator).

Also rename the terribly named 'self.forbidlabels' to 'self.optenabled' which is more descriptive.
This commit is contained in:
Sei Lisa 2018-04-09 18:42:31 +02:00
parent 4a554d60e8
commit 1afe1643c0
2 changed files with 11 additions and 4 deletions

View file

@ -1628,6 +1628,9 @@ list lazy_list_set(list L, integer i, list v)
if self.tok[0] not in (']', ')', ';'): if self.tok[0] not in (']', ')', ';'):
while True: while True:
expr = self.Parse_expression() expr = self.Parse_expression()
if expr.nt == 'SUBIDX' and expr.t is None:
# Don't accept an untyped lazy list in expression lists
raise EParseTypeMismatch(self)
if False is not expected_types is not None: if False is not expected_types is not None:
if idx >= len(expected_types): if idx >= len(expected_types):
raise EParseFunctionMismatch(self) raise EParseFunctionMismatch(self)
@ -1635,7 +1638,8 @@ list lazy_list_set(list L, integer i, list v)
expr = self.autocastcheck(expr, expected_types[idx]); expr = self.autocastcheck(expr, expected_types[idx]);
except EParseTypeMismatch: except EParseTypeMismatch:
raise EParseFunctionMismatch(self) raise EParseFunctionMismatch(self)
elif expected_types is False: # don't accept void expressions elif expected_types is False and self.optenabled:
# don't accept void expressions if optimization is on
if expr.t not in types: if expr.t not in types:
raise EParseTypeMismatch(self) raise EParseTypeMismatch(self)
idx += 1 idx += 1
@ -1695,7 +1699,7 @@ list lazy_list_set(list L, integer i, list v)
return nr(nt=';', t=None) return nr(nt=';', t=None)
if tok0 == '@': if tok0 == '@':
if not AllowDecl and self.forbidlabels: if not AllowDecl and self.optenabled:
raise EParseInvalidLabelOpt(self) raise EParseInvalidLabelOpt(self)
self.NextToken() self.NextToken()
self.expect('IDENT') self.expect('IDENT')
@ -2775,7 +2779,7 @@ list lazy_list_set(list L, integer i, list v)
# includes a label as the immediate child of FOR, IF, DO or WHILE. # includes a label as the immediate child of FOR, IF, DO or WHILE.
# If optimization is on, such a label will raise an error. That # If optimization is on, such a label will raise an error. That
# coding pattern is normally easy to work around anyway. # coding pattern is normally easy to work around anyway.
self.forbidlabels = 'optimize' in options self.optenabled = 'optimize' in options
# Symbol table: # Symbol table:
# This is a list of all local and global symbol tables. # This is a list of all local and global symbol tables.

View file

@ -128,7 +128,7 @@ class Test02_Parser(UnitTestCase):
self.assertRaises(EParseFunctionMismatch, self.parser.parse, '''f(integer i){f(f(1));}''') self.assertRaises(EParseFunctionMismatch, self.parser.parse, '''f(integer i){f(f(1));}''')
self.assertRaises(EParseFunctionMismatch, self.parser.parse, '''f(integer i){f();}''') self.assertRaises(EParseFunctionMismatch, self.parser.parse, '''f(integer i){f();}''')
self.assertRaises(EParseDeclarationScope, self.parser.parse, '''f(){if (1) integer i;}''') self.assertRaises(EParseDeclarationScope, self.parser.parse, '''f(){if (1) integer i;}''')
self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){[f()];}''') self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){[f()];}''', ('optimize',))
self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){3.||2;}''') self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){3.||2;}''')
self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){3||2.;}''') self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){3||2.;}''')
self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){3.|2;}''') self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){3.|2;}''')
@ -185,6 +185,9 @@ class Test02_Parser(UnitTestCase):
self.assertRaises(EParseUndefined, self.parser.parse, '''key a=b;key b;default{timer(){}}''', self.assertRaises(EParseUndefined, self.parser.parse, '''key a=b;key b;default{timer(){}}''',
['extendedglobalexpr']) ['extendedglobalexpr'])
self.parser.parse('''f(){[f()];}default{timer(){}}''')
# Force a list constant down its throat, to test coverage of LIST_VALUE # Force a list constant down its throat, to test coverage of LIST_VALUE
self.parser.constants['LISTCONST']=[1,2,3] self.parser.constants['LISTCONST']=[1,2,3]
print self.outscript.output(self.parser.parse('default{timer(){LISTCONST;}}')) print self.outscript.output(self.parser.parse('default{timer(){LISTCONST;}}'))