diff options
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | libsolidity/ast/Types.cpp | 6 | ||||
-rw-r--r-- | test/libsolidity/syntaxTests/literal_comparisons.sol | 7 |
3 files changed, 11 insertions, 3 deletions
diff --git a/Changelog.md b/Changelog.md index 9a910a1a..8c9ba460 100644 --- a/Changelog.md +++ b/Changelog.md @@ -27,6 +27,7 @@ Bugfixes: * DocString Parser: Fix error message for empty descriptions. * Standard JSON: Support ``constantinople`` as ``evmVersion`` properly. * Type Checker: Fix detection of recursive structs. + * Type Checker: Fix asymmetry bug when comparing with literal numbers. * Type System: Improve error message when attempting to shift by a fractional amount. * Type System: Make external library functions accessible. * Type System: Prevent encoding of weird types. diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index de359ec6..21353080 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -839,10 +839,10 @@ TypePointer RationalNumberType::binaryOperatorResult(Token::Value _operator, Typ { if (_other->category() == Category::Integer || _other->category() == Category::FixedPoint) { - auto mobile = mobileType(); - if (!mobile) + auto commonType = Type::commonType(shared_from_this(), _other); + if (!commonType) return TypePointer(); - return mobile->binaryOperatorResult(_operator, _other); + return commonType->binaryOperatorResult(_operator, _other); } else if (_other->category() != category()) return TypePointer(); diff --git a/test/libsolidity/syntaxTests/literal_comparisons.sol b/test/libsolidity/syntaxTests/literal_comparisons.sol new file mode 100644 index 00000000..dd2afcaa --- /dev/null +++ b/test/libsolidity/syntaxTests/literal_comparisons.sol @@ -0,0 +1,7 @@ +contract test { + function f(int8 x) public pure { + if (x == 1) {} + if (1 == x) {} + } +} +// ---- |