diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2023-06-14 20:36:50 -0400 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2023-06-14 23:12:09 -0400 |
commit | f93f443a536c36b5a22284cb8d0bb276e766743c (patch) | |
tree | 3f96cf08d3d298d09ddf933818348e2316f47adb | |
parent | d558291abe9d851584e74f0154be819bc4baf207 (diff) | |
download | meson-f93f443a536c36b5a22284cb8d0bb276e766743c.zip meson-f93f443a536c36b5a22284cb8d0bb276e766743c.tar.gz meson-f93f443a536c36b5a22284cb8d0bb276e766743c.tar.bz2 |
detect and warn on non-commutative int/bool operations
an int only accepts operations on other ints, just like other primitive
types only accept operations on values of the same type.
But due to using isinstance in baseobjects "operator_call", an int
primitive allowed operations on a bool, even though reversing the
operator and having a bool perform operations on an int, would fail with
a type error.
Really, we should fail with a type error in both directions. But for
stability reasons, make this a loud warning and break --fatal-meson-warnings
builds.
-rw-r--r-- | mesonbuild/interpreter/primitives/integer.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/mesonbuild/interpreter/primitives/integer.py b/mesonbuild/interpreter/primitives/integer.py index f433f57..b7f3532 100644 --- a/mesonbuild/interpreter/primitives/integer.py +++ b/mesonbuild/interpreter/primitives/integer.py @@ -3,13 +3,8 @@ from __future__ import annotations from ...interpreterbase import ( - ObjectHolder, - MesonOperator, - typed_operator, - noKwargs, - noPosargs, - - InvalidArguments + FeatureBroken, InvalidArguments, MesonOperator, ObjectHolder, + noKwargs, noPosargs, typed_operator, ) import typing as T @@ -53,6 +48,13 @@ class IntegerHolder(ObjectHolder[int]): def display_name(self) -> str: return 'int' + def operator_call(self, operator: MesonOperator, other: TYPE_var) -> TYPE_var: + if isinstance(other, bool): + FeatureBroken.single_use('int operations with non-int', '1.2.0', self.subproject, + 'It is not commutative and only worked because of leaky Python abstractions.', + location=self.current_node) + return super().operator_call(operator, other) + @noKwargs @noPosargs def is_even_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> bool: |