Skip to content

Commit ff3be8e

Browse files
committed
Check typecast in array parameters
Checks a function with array parameters is being called correctly. Also test updated.
1 parent 1ba939b commit ff3be8e

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

symbols/typecast.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from .type_ import SymbolTYPE
1414
from .type_ import Type as TYPE
1515
from .number import SymbolNUMBER
16+
from .vararray import SymbolVARARRAY
1617

1718
from api.errmsg import syntax_error
1819
from api import errmsg
@@ -60,6 +61,11 @@ def make_node(cls, new_type, node, lineno):
6061
if new_type == node.type_:
6162
return node # Do nothing. Return as is
6263

64+
# TODO: Create a base scalar type
65+
if isinstance(node, SymbolVARARRAY):
66+
syntax_error(lineno, "Array {} type does not match parameter type".format(node.name))
67+
return None
68+
6369
STRTYPE = TYPE.string
6470
# Typecasting, at the moment, only for number
6571
if node.type_ == STRTYPE:

tests/functional/pararray2.bas

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
FUNCTION test(q() as UInteger) as Byte
3+
DIM i as Ubyte = 3
4+
q(i) = 7
5+
END FUNCTION
6+
7+
DIM q(10) as UByte
8+
test(q)
9+

tests/functional/test_errmsg.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ mcleod3.bas:3: 'GenerateSpaces' is neither an array nor a function.
4141
mcleod3.bas:1: warning: Parameter 'path' is never used
4242
mcleod3.bas:6: warning: Parameter 'n' is never used
4343
>>> process_file('poke3.bas')
44-
poke3.bas:4: Variable 'a' is an array and cannot be used in this context
44+
poke3.bas:4: Syntax Error. Unexpected token ',' <COMMA>
4545
>>> process_file('poke5.bas')
46-
poke5.bas:4: Variable 'a' is an array and cannot be used in this context
46+
poke5.bas:4: Syntax Error. Unexpected token ',' <COMMA>
4747
>>> process_file('arrlabels10.bas')
4848
arrlabels10.bas:3: warning: Using default implicit type 'float' for 'a'
4949
arrlabels10.bas:3: Can't convert non-numeric value to float at compile time
@@ -84,7 +84,7 @@ errletfunc.bas:5: Cannot assign a value to 'x'. It's not a variable
8484
>>> process_file('read0.bas')
8585
read0.bas:12: 'x' is SUBROUTINE not a FUNCTION
8686
>>> process_file('read1.bas')
87-
read1.bas:11: Variable 'x' is an array and cannot be used in this context
87+
read1.bas:11: Cannot read 'x'. It's an array
8888
>>> process_file('read3.bas')
8989
read3.bas:9: 'x' is neither an array nor a function.
9090
>>> process_file('read6.bas')
@@ -141,4 +141,6 @@ params_implicit.bas:2: warning: Parameter 'y' is never used
141141
array_err.bas:2: Mismatched vector size. Expected 11 elements, got 1.
142142
>>> process_file('arrbase1.bas')
143143
>>> process_file('param_byref_warn.bas')
144+
>>> process_file('pararray2.bas')
145+
pararray2.bas:8: Array q type does not match parameter type
144146

0 commit comments

Comments
 (0)