aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-10-03 22:28:29 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-10-06 02:02:30 +0800
commit81519845bc35043c8460252e62a30a137f93432d (patch)
treee6f7b4daf9db485a2932524f9084b615595de82d
parentd0fa56a217f50458b128b0a570724cdac0a5ee1a (diff)
downloaddexon-solidity-81519845bc35043c8460252e62a30a137f93432d.tar.gz
dexon-solidity-81519845bc35043c8460252e62a30a137f93432d.tar.zst
dexon-solidity-81519845bc35043c8460252e62a30a137f93432d.zip
Require location keyword for local variables (0.5.0)
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/analysis/ReferencesResolver.cpp18
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp14
3 files changed, 27 insertions, 6 deletions
diff --git a/Changelog.md b/Changelog.md
index ace9bc36..d558fd6f 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -9,6 +9,7 @@ Features:
* Syntax Checker: Unary ``+`` is now a syntax error as experimental 0.5.0 feature.
* Type Checker: Disallow non-pure constant state variables as experimental 0.5.0 feature.
* Type Checker: Do not add members of ``address`` to contracts as experimental 0.5.0 feature.
+ * Type Checker: Require ``storage`` or ``memory`` keyword for local variables as experimental 0.5.0 feature.
Bugfixes:
* Parser: Fix source location of VariableDeclarationStatement.
diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp
index 20016112..29278332 100644
--- a/libsolidity/analysis/ReferencesResolver.cpp
+++ b/libsolidity/analysis/ReferencesResolver.cpp
@@ -298,11 +298,19 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable)
{
typeLoc = DataLocation::Storage;
if (_variable.isLocalVariable())
- m_errorReporter.warning(
- _variable.location(),
- "Variable is declared as a storage pointer. "
- "Use an explicit \"storage\" keyword to silence this warning."
- );
+ {
+ if (_variable.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050))
+ typeError(
+ _variable.location(),
+ "Storage location must be specified as either \"memory\" or \"storage\"."
+ );
+ else
+ m_errorReporter.warning(
+ _variable.location(),
+ "Variable is declared as a storage pointer. "
+ "Use an explicit \"storage\" keyword to silence this warning."
+ );
+ }
}
}
else
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 738e0a87..a6fc4e34 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -6523,7 +6523,19 @@ BOOST_AUTO_TEST_CASE(warn_unspecified_storage)
}
}
)";
- CHECK_WARNING(text, "is declared as a storage pointer. Use an explicit \"storage\" keyword to silence this warning");
+ CHECK_WARNING(text, "Variable is declared as a storage pointer. Use an explicit \"storage\" keyword to silence this warning");
+ text = R"(
+ pragma experimental "v0.5.0";
+ contract C {
+ struct S { uint a; }
+ S x;
+ function f() view public {
+ S y = x;
+ y;
+ }
+ }
+ )";
+ CHECK_ERROR(text, TypeError, "Storage location must be specified as either \"memory\" or \"storage\".");
}
BOOST_AUTO_TEST_CASE(implicit_conversion_disallowed)