aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-09-08 18:57:27 +0800
committerchriseth <c@ethdev.com>2015-09-08 22:51:14 +0800
commit985eb80695bf9c2a757397374a0ec30ea09d17c1 (patch)
treefda7e5e9e19744f78e24cc4e87a36d8af545fb0b /libsolidity
parentea981cb0f5e5b131a56e420db97e944644ac95d6 (diff)
downloaddexon-solidity-985eb80695bf9c2a757397374a0ec30ea09d17c1.tar.gz
dexon-solidity-985eb80695bf9c2a757397374a0ec30ea09d17c1.tar.zst
dexon-solidity-985eb80695bf9c2a757397374a0ec30ea09d17c1.zip
Fix for constant strings.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/AST.cpp22
-rw-r--r--libsolidity/ExpressionCompiler.cpp4
-rw-r--r--libsolidity/NameAndTypeResolver.cpp8
3 files changed, 28 insertions, 6 deletions
diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp
index 8889edf0..ae125e52 100644
--- a/libsolidity/AST.cpp
+++ b/libsolidity/AST.cpp
@@ -81,15 +81,16 @@ void ContractDefinition::checkTypeRequirements()
if (!function->isFullyImplemented())
setFullyImplemented(false);
}
+
+ for (ASTPointer<VariableDeclaration> const& variable: m_stateVariables)
+ variable->checkTypeRequirements();
+
for (ASTPointer<ModifierDefinition> const& modifier: functionModifiers())
modifier->checkTypeRequirements();
for (ASTPointer<FunctionDefinition> const& function: definedFunctions())
function->checkTypeRequirements();
- for (ASTPointer<VariableDeclaration> const& variable: m_stateVariables)
- variable->checkTypeRequirements();
-
checkExternalTypeClashes();
// check for hash collisions in function signatures
set<FixedHash<4>> hashes;
@@ -559,9 +560,18 @@ void VariableDeclaration::checkTypeRequirements()
BOOST_THROW_EXCEPTION(createTypeError("Illegal use of \"constant\" specifier."));
if (!m_value)
BOOST_THROW_EXCEPTION(createTypeError("Uninitialized \"constant\" variable."));
- else if (m_type && !m_type->isValueType())
- // TODO: const is implemented only for uint, bytesXX and enums types.
- BOOST_THROW_EXCEPTION(createTypeError("Illegal use of \"constant\" specifier. \"constant\" is not implemented for this type yet."));
+ if (m_type && !m_type->isValueType())
+ {
+ // TODO: const is implemented only for uint, bytesXX, string and enums types.
+ bool constImplemented = false;
+ if (auto arrayType = dynamic_cast<ArrayType const*>(m_type.get()))
+ constImplemented = arrayType->isByteArray();
+ if (!constImplemented)
+ BOOST_THROW_EXCEPTION(createTypeError(
+ "Illegal use of \"constant\" specifier. \"constant\" "
+ " is not yet implemented for this type."
+ ));
+ }
}
if (m_type)
{
diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp
index 449267a7..d5a8362e 100644
--- a/libsolidity/ExpressionCompiler.cpp
+++ b/libsolidity/ExpressionCompiler.cpp
@@ -71,6 +71,7 @@ void ExpressionCompiler::appendConstStateVariableAccessor(VariableDeclaration co
{
solAssert(_varDecl.isConstant(), "");
_varDecl.value()->accept(*this);
+ utils().convertType(*_varDecl.value()->type(), *_varDecl.type());
// append return
m_context << eth::dupInstruction(_varDecl.type()->sizeOnStack() + 1);
@@ -918,7 +919,10 @@ void ExpressionCompiler::endVisit(Identifier const& _identifier)
if (!variable->isConstant())
setLValueFromDeclaration(*declaration, _identifier);
else
+ {
variable->value()->accept(*this);
+ utils().convertType(*variable->value()->type(), *variable->type());
+ }
}
else if (dynamic_cast<ContractDefinition const*>(declaration))
{
diff --git a/libsolidity/NameAndTypeResolver.cpp b/libsolidity/NameAndTypeResolver.cpp
index 96800ec3..c3b49abd 100644
--- a/libsolidity/NameAndTypeResolver.cpp
+++ b/libsolidity/NameAndTypeResolver.cpp
@@ -457,6 +457,14 @@ void ReferencesResolver::endVisit(VariableDeclaration& _variable)
}
else
{
+ if (_variable.isConstant())
+ {
+ if (loc != Location::Default && loc != Location::Memory)
+ BOOST_THROW_EXCEPTION(_variable.createTypeError(
+ "Storage location has to be \"memory\" (or unspecified) for constants."
+ ));
+ loc = Location::Memory;
+ }
if (loc == Location::Default)
loc = _variable.isCallableParameter() ? Location::Memory : Location::Storage;
bool isPointer = !_variable.isStateVariable();