4ede703687
Constant expression like "2 ** 3" will now be folded, and the special form "X = const(2 ** 3)" will now compile because the argument to the const is now a constant. Fixes issue #5865.
27 lines
605 B
Python
27 lines
605 B
Python
# make sure syntax error works correctly for bad const definition
|
|
|
|
from micropython import const
|
|
|
|
|
|
def test_syntax(code):
|
|
try:
|
|
exec(code)
|
|
except SyntaxError:
|
|
print("SyntaxError")
|
|
|
|
|
|
# argument not a constant
|
|
test_syntax("a = const(x)")
|
|
|
|
# redefined constant
|
|
test_syntax("A = const(1); A = const(2)")
|
|
|
|
# these operations are not supported within const
|
|
test_syntax("A = const(1 @ 2)")
|
|
test_syntax("A = const(1 / 2)")
|
|
test_syntax("A = const(1 ** -2)")
|
|
test_syntax("A = const(1 << -2)")
|
|
test_syntax("A = const(1 >> -2)")
|
|
test_syntax("A = const(1 % 0)")
|
|
test_syntax("A = const(1 // 0)")
|