interpreter: Fix missing featuer check (fixes #9425)

pull/9445/head
Daniel Mensinger 3 years ago committed by Eli Schwartz
parent ffc8721465
commit 2d8da3cb11
  1. 4
      mesonbuild/interpreter/primitives/array.py
  2. 6
      mesonbuild/interpreterbase/interpreterbase.py
  3. 7
      test cases/warning/6 list add/meson.build
  4. 7
      test cases/warning/6 list add/test.json

@ -12,12 +12,14 @@ from ...interpreterbase import (
noPosargs,
noArgsFlattening,
typed_pos_args,
FeatureNew,
TYPE_var,
TYPE_kwargs,
InvalidArguments,
)
from ...mparser import PlusAssignmentNode
if T.TYPE_CHECKING:
# Object holders need the actual interpreter
@ -92,6 +94,8 @@ class ArrayHolder(ObjectHolder[T.List[TYPE_var]], IterableObject):
@typed_operator(MesonOperator.PLUS, object)
def op_plus(self, other: TYPE_var) -> T.List[TYPE_var]:
if not isinstance(other, list):
if not isinstance(self.current_node, PlusAssignmentNode):
FeatureNew.single_use('list.<plus>', '0.60.0', self.subproject, 'The right hand operand was not a list.')
other = [other]
return self.held_object + other

@ -303,6 +303,7 @@ class InterpreterBase:
if operator in (MesonOperator.IN, MesonOperator.NOT_IN):
val1, val2 = val2, val1
val1.current_node = node
return self._holderify(val1.operator_call(operator, _unholder(val2)))
def evaluate_andstatement(self, cur: mparser.AndNode) -> InterpreterObject:
@ -333,6 +334,7 @@ class InterpreterBase:
v = self.evaluate_statement(cur.value)
if isinstance(v, Disabler):
return v
v.current_node = cur
return self._holderify(v.operator_call(MesonOperator.UMINUS, None))
def evaluate_arithmeticstatement(self, cur: mparser.ArithmeticNode) -> InterpreterObject:
@ -350,6 +352,7 @@ class InterpreterBase:
'div': MesonOperator.DIV,
'mod': MesonOperator.MOD,
}
l.current_node = cur
res = l.operator_call(mapping[cur.operation], _unholder(r))
return self._holderify(res)
@ -358,6 +361,7 @@ class InterpreterBase:
result = self.evaluate_statement(node.condition)
if isinstance(result, Disabler):
return result
result.current_node = node
result_bool = result.operator_call(MesonOperator.BOOL, None)
if result_bool:
return self.evaluate_statement(node.trueblock)
@ -420,6 +424,7 @@ class InterpreterBase:
# Remember that all variables are immutable. We must always create a
# full new variable and then assign it.
old_variable = self.get_variable(varname)
old_variable.current_node = node
new_value = self._holderify(old_variable.operator_call(MesonOperator.PLUS, _unholder(addition)))
self.set_variable(varname, new_value)
@ -432,6 +437,7 @@ class InterpreterBase:
if iobject is None:
raise InterpreterException('Tried to evaluate indexing on None')
iobject.current_node = node
return self._holderify(iobject.operator_call(MesonOperator.INDEX, index))
def function_call(self, node: mparser.FunctionNode) -> T.Optional[InterpreterObject]:

@ -0,0 +1,7 @@
project('test list add', meson_version: '>=0.59.0')
l1 = [1, 2, 3]
l2 = l1 + 4
l2 += 5
message(l2)

@ -0,0 +1,7 @@
{
"stdout": [
{
"line": "WARNING: Project targeting '>=0.59.0' but tried to use feature introduced in '0.60.0': list.<plus>. The right hand operand was not a list."
}
]
}
Loading…
Cancel
Save