Interpreter.eval_NodeAttrAccess must be able to look up attributes of unevaluated expressions.
It seems there is a test case missing to test this feature. This is needed for print.
Expressions that should trigger the bug are:
data a, b: Float variable
print(sqrt(a))
print(a + b)
(a + b).__add__(2)
data a, b: Float variable
print(sqrt(a))
print(a + b)
(a + b).__add__(2)
An other related issue:
You can look up attributes of the ast.Node itself:
(a + b).function
or
(a + b).loc
This should off course not be possible. Therefore unevaluated expressions need special treatment in Interpreter.eval_NodeAttrAccess(...).
A safe treatment of this situation is:
- Create a variable of the right type and role, and assign the expression to it.
- Do attribute lookups with this variable.
- Optimize the variable away later.
Nearly all lookups are however for methods. They can be processed without constructing an intermediate variable.
See also:
* Bug #672227 - New architecture for code generation in expressions
* NewCodeGenerationArchitecture
http://sourceforge.net/apps/trac/freeode/ticket/7
An other issue:
You can look up attributes of the ast.Node itself:
(a + b).function
or
(a + b).loc
This should off course not be possible. Therefore unevaluated expressions need special treatment in Interpreter. eval_NodeAttrAc cess(.. .).
A safe treatment of this situation is:
- Create a variable of the right type and role, and assign the expression to it.
- Do attribute lookups with this variable.
- Optimize the variable away later.
Nearly all lookups are however for methods. They can be processed without constructing an intermediate variable.