aboutsummaryrefslogtreecommitdiffstats
path: root/test/libyul/Parser.cpp
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2019-01-15 23:57:32 +0800
committerGitHub <noreply@github.com>2019-01-15 23:57:32 +0800
commit6146c59a1aa4c082226a6051aa89a28446b0041d (patch)
treecbaea6e325d355e4050f084936497a0816bb5bcc /test/libyul/Parser.cpp
parentf9ca5b78fb41c18fe0b538d0be909c9026269fbd (diff)
parent4c8f8e949143d0c680a8257adbcc768d908fae9a (diff)
downloaddexon-solidity-6146c59a1aa4c082226a6051aa89a28446b0041d.tar.gz
dexon-solidity-6146c59a1aa4c082226a6051aa89a28446b0041d.tar.zst
dexon-solidity-6146c59a1aa4c082226a6051aa89a28446b0041d.zip
Merge pull request #5793 from ethereum/switchLiteralSameValue
[Yul] Require equal types for switch cases and detect duplicates by number value.
Diffstat (limited to 'test/libyul/Parser.cpp')
-rw-r--r--test/libyul/Parser.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/libyul/Parser.cpp b/test/libyul/Parser.cpp
index 897f18ae..84f5c14b 100644
--- a/test/libyul/Parser.cpp
+++ b/test/libyul/Parser.cpp
@@ -304,6 +304,19 @@ BOOST_AUTO_TEST_CASE(if_statement_invalid)
BOOST_CHECK(successParse("{ if 42:u256 { } }"));
}
+BOOST_AUTO_TEST_CASE(switch_case_types)
+{
+ CHECK_ERROR("{ switch 0:u256 case 0:u256 {} case 1:u32 {} }", TypeError, "Switch cases have non-matching types.");
+ // The following should be an error in the future, but this is not yet detected.
+ BOOST_CHECK(successParse("{ switch 0:u256 case 0:u32 {} case 1:u32 {} }"));
+}
+
+BOOST_AUTO_TEST_CASE(switch_duplicate_case)
+{
+ CHECK_ERROR("{ switch 0:u256 case 0:u256 {} case 0x0:u256 {} }", DeclarationError, "Duplicate case defined.");
+ BOOST_CHECK(successParse("{ switch 0:u256 case 42:u256 {} case 0x42:u256 {} }"));
+}
+
BOOST_AUTO_TEST_CASE(builtins_parser)
{
struct SimpleDialect: public Dialect