From 0e56ec2dbdbbd463d608c42e0aa117357e18936a Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 17 May 2017 22:00:02 -0400 Subject: [PATCH] Don't allow non-equality comparisons across types. --- mesonbuild/interpreterbase.py | 5 +++++ test cases/failing/52 inconsistent comparison/meson.build | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 test cases/failing/52 inconsistent comparison/meson.build diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py index 8b951b30a..fb87ea20b 100644 --- a/mesonbuild/interpreterbase.py +++ b/mesonbuild/interpreterbase.py @@ -221,6 +221,11 @@ class InterpreterBase: return val1 == val2 elif node.ctype == '!=': return val1 != val2 + elif not isinstance(val1, type(val2)): + raise InterpreterException( + 'Values of different types ({}, {}) cannot be compared using {}.'.format(type(val1).__name__, + type(val2).__name__, + node.ctype)) elif not self.is_elementary_type(val1): raise InterpreterException('{} can only be compared for equality.'.format(node.left.value)) elif not self.is_elementary_type(val2): diff --git a/test cases/failing/52 inconsistent comparison/meson.build b/test cases/failing/52 inconsistent comparison/meson.build new file mode 100644 index 000000000..7694c2cd2 --- /dev/null +++ b/test cases/failing/52 inconsistent comparison/meson.build @@ -0,0 +1,7 @@ +project('kwarg before arg', 'c') + +# All of these should fail, though only the first one will error out if +# everything's working correctly. +assert([] < 'st', 'should fail') +assert([] < 1, 'should fail') +assert(2 < 'st', 'should fail')