Disallow non-pure constant state variables in 0.5.0

This commit is contained in:
Federico Bond
2017-10-03 15:30:16 +01:00
committed by Alex Beregszaszi
parent 5c28458920
commit 2b82352692
3 changed files with 42 additions and 9 deletions
+14 -5
View File
@@ -645,14 +645,23 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
if (!allowed)
m_errorReporter.typeError(_variable.location(), "Constants of non-value type not yet implemented.");
}
if (!_variable.value())
m_errorReporter.typeError(_variable.location(), "Uninitialized \"constant\" variable.");
else if (!_variable.value()->annotation().isPure)
m_errorReporter.warning(
_variable.value()->location(),
"Initial value for constant variable has to be compile-time constant. "
"This will fail to compile with the next breaking version change."
);
{
if (_variable.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050))
m_errorReporter.typeError(
_variable.value()->location(),
"Initial value for constant variable has to be compile-time constant."
);
else
m_errorReporter.warning(
_variable.value()->location(),
"Initial value for constant variable has to be compile-time constant. "
"This will fail to compile with the next breaking version change."
);
}
}
if (!_variable.isStateVariable())
{