aboutsummaryrefslogtreecommitdiffstats
path: root/libyul/AsmAnalysis.cpp
diff options
context:
space:
mode:
authorDaniel Kirchner <daniel@ekpyron.org>2019-01-15 20:40:10 +0800
committerDaniel Kirchner <daniel@ekpyron.org>2019-01-15 23:32:21 +0800
commit4c8f8e949143d0c680a8257adbcc768d908fae9a (patch)
treecbaea6e325d355e4050f084936497a0816bb5bcc /libyul/AsmAnalysis.cpp
parentf9ca5b78fb41c18fe0b538d0be909c9026269fbd (diff)
downloaddexon-solidity-4c8f8e949143d0c680a8257adbcc768d908fae9a.tar.gz
dexon-solidity-4c8f8e949143d0c680a8257adbcc768d908fae9a.tar.zst
dexon-solidity-4c8f8e949143d0c680a8257adbcc768d908fae9a.zip
Disallow mismatching types in switch cases and detect duplicates by value for number literals.
Diffstat (limited to 'libyul/AsmAnalysis.cpp')
-rw-r--r--libyul/AsmAnalysis.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/libyul/AsmAnalysis.cpp b/libyul/AsmAnalysis.cpp
index 6a7b2b61..a5552c51 100644
--- a/libyul/AsmAnalysis.cpp
+++ b/libyul/AsmAnalysis.cpp
@@ -24,6 +24,7 @@
#include <libyul/AsmScopeFiller.h>
#include <libyul/AsmScope.h>
#include <libyul/AsmAnalysisInfo.h>
+#include <libyul/Utilities.h>
#include <liblangutil/ErrorReporter.h>
@@ -390,7 +391,29 @@ bool AsmAnalyzer::operator()(Switch const& _switch)
if (!expectExpression(*_switch.expression))
success = false;
- set<tuple<LiteralKind, YulString>> cases;
+ if (m_dialect->flavour == AsmFlavour::Yul)
+ {
+ YulString caseType;
+ bool mismatchingTypes = false;
+ for (auto const& _case: _switch.cases)
+ if (_case.value)
+ {
+ if (caseType.empty())
+ caseType = _case.value->type;
+ else if (caseType != _case.value->type)
+ {
+ mismatchingTypes = true;
+ break;
+ }
+ }
+ if (mismatchingTypes)
+ m_errorReporter.typeError(
+ _switch.location,
+ "Switch cases have non-matching types."
+ );
+ }
+
+ set<Literal const*, Less<Literal*>> cases;
for (auto const& _case: _switch.cases)
{
if (_case.value)
@@ -404,12 +427,11 @@ bool AsmAnalyzer::operator()(Switch const& _switch)
m_stackHeight--;
/// Note: the parser ensures there is only one default case
- auto val = make_tuple(_case.value->kind, _case.value->value);
- if (!cases.insert(val).second)
+ if (!cases.insert(_case.value.get()).second)
{
m_errorReporter.declarationError(
_case.location,
- "Duplicate case defined"
+ "Duplicate case defined."
);
success = false;
}