From e0fbdd57e6ca44472850c05a74f56c7ed555cf2d Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 6 Aug 2015 15:33:06 +0200 Subject: Do not allow boolean operators for integers. Fixes #2496 --- libsolidity/SolidityNameAndTypeResolution.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp index 6b116f25..e59217bf 100644 --- a/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1883,6 +1883,22 @@ BOOST_AUTO_TEST_CASE(positive_integers_to_unsigned_out_of_bound) BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); } +BOOST_AUTO_TEST_CASE(integer_boolean_operators) +{ + char const* sourceCode1 = R"( + contract test { function() { uint x = 1; uint y = 2; x || y; } } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode1), TypeError); + char const* sourceCode2 = R"( + contract test { function() { uint x = 1; uint y = 2; x && y; } } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode2), TypeError); + char const* sourceCode3 = R"( + contract test { function() { uint x = 1; !x; } } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode3), TypeError); +} + BOOST_AUTO_TEST_CASE(overwrite_memory_location_external) { char const* sourceCode = R"( -- cgit From 4288543847307de17d7fbde393a1a3f647be5f05 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 6 Aug 2015 15:39:42 +0200 Subject: Disallow comparison for reference types. Fixes #2690 --- libsolidity/SolidityNameAndTypeResolution.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp index e59217bf..ba5a5a60 100644 --- a/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1899,6 +1899,18 @@ BOOST_AUTO_TEST_CASE(integer_boolean_operators) BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode3), TypeError); } +BOOST_AUTO_TEST_CASE(reference_compare_operators) +{ + char const* sourceCode1 = R"( + contract test { bytes a; bytes b; function() { a == b; } } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode1), TypeError); + char const* sourceCode2 = R"( + contract test { struct s {uint a;}; s x; s y; function() { x == y; } } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode2), TypeError); +} + BOOST_AUTO_TEST_CASE(overwrite_memory_location_external) { char const* sourceCode = R"( -- cgit