diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2021-08-29 10:25:40 +0200 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2021-08-31 23:01:21 +0200 |
commit | a6c9a151d3ce51d53fc7f34722a7422c3c0faff4 (patch) | |
tree | e8cee4bcfda408043acef70afe7a4905c84cee60 | |
parent | b60bd0e299460c436acba43de27ac52afb11026b (diff) | |
download | meson-a6c9a151d3ce51d53fc7f34722a7422c3c0faff4.zip meson-a6c9a151d3ce51d53fc7f34722a7422c3c0faff4.tar.gz meson-a6c9a151d3ce51d53fc7f34722a7422c3c0faff4.tar.bz2 |
interpreter: Make comparisons of different types a hard error
-rw-r--r-- | docs/markdown/snippets/comp_error.md | 5 | ||||
-rw-r--r-- | mesonbuild/interpreterbase/interpreterbase.py | 12 | ||||
-rw-r--r-- | test cases/common/16 comparison/meson.build | 11 |
3 files changed, 13 insertions, 15 deletions
diff --git a/docs/markdown/snippets/comp_error.md b/docs/markdown/snippets/comp_error.md new file mode 100644 index 0000000..6d1bf46 --- /dev/null +++ b/docs/markdown/snippets/comp_error.md @@ -0,0 +1,5 @@ +## Comparing two objects with different types is now an error + +Using the `==` and `!=` operators to compare objects of different (for instance +`[1] == 1`) types was deprecated and undefined behavior since 0.45.0 and is +now a hard error. diff --git a/mesonbuild/interpreterbase/interpreterbase.py b/mesonbuild/interpreterbase/interpreterbase.py index 2fa77ee..289e1d7 100644 --- a/mesonbuild/interpreterbase/interpreterbase.py +++ b/mesonbuild/interpreterbase/interpreterbase.py @@ -47,6 +47,7 @@ from ._unholder import _unholder import os, copy, re, pathlib import typing as T +import textwrap if T.TYPE_CHECKING: from ..interpreter import Interpreter @@ -306,11 +307,14 @@ class InterpreterBase: valid = self.validate_comparison_types(val1, val2) # Ordering comparisons of different types isn't allowed since PR #1810 # (0.41.0). Since PR #2884 we also warn about equality comparisons of - # different types, which will one day become an error. + # different types, which is now an error. if not valid and (node.ctype == '==' or node.ctype == '!='): - mlog.warning('''Trying to compare values of different types ({}, {}) using {}. -The result of this is undefined and will become a hard error in a future Meson release.''' - .format(type(val1).__name__, type(val2).__name__, node.ctype), location=node) + raise InvalidArguments(textwrap.dedent( + f''' + Trying to compare values of different types ({type(val1).__name__}, {type(val2).__name__}) using {node.ctype}. + This was deprecated and undefined behavior previously and is as of 0.60.0 a hard error. + ''' + )) if node.ctype == '==': return val1 == val2 elif node.ctype == '!=': diff --git a/test cases/common/16 comparison/meson.build b/test cases/common/16 comparison/meson.build index bba0168..1d250f9 100644 --- a/test cases/common/16 comparison/meson.build +++ b/test cases/common/16 comparison/meson.build @@ -127,17 +127,6 @@ test('equaltrue', exe14) test('nequaltrue', exe15) test('nequalfalse', exe16) -# Equality comparisons of different elementary types -# (these all cause warnings currently, will become an error in future) - -assert([] != 'st', 'not equal') -assert([] != 1, 'not equal') -assert(2 != 'st', 'not equal') - -assert(not ([] == 'st'), 'not equal') -assert(not ([] == 1), 'not equal') -assert(not (2 == 'st'), 'not equal') - # "in" and "not in" operators assert(1 in [1, 2], '''1 should be in [1, 2]''') |