mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #8977 from ethereum/mapping-type-error
Error when Mapping type in (non-local) storage is assigned to
This commit is contained in:
commit
f70ff0dfaa
@ -11,6 +11,7 @@ Compiler Features:
|
||||
|
||||
Bugfixes:
|
||||
* Optimizer: Fixed a bug in BlockDeDuplicator.
|
||||
* Type Checker: Disallow assignments to storage variables of type ``mapping``.
|
||||
|
||||
|
||||
### 0.6.8 (2020-05-14)
|
||||
|
@ -453,7 +453,15 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
|
||||
if (contractType->contractDefinition().isLibrary())
|
||||
m_errorReporter.typeError(1273_error, _variable.location(), "The type of a variable cannot be a library.");
|
||||
if (_variable.value())
|
||||
expectType(*_variable.value(), *varType);
|
||||
{
|
||||
if (_variable.isStateVariable() && dynamic_cast<MappingType const*>(varType))
|
||||
{
|
||||
m_errorReporter.typeError(6280_error, _variable.location(), "Mappings cannot be assigned to.");
|
||||
_variable.value()->accept(*this);
|
||||
}
|
||||
else
|
||||
expectType(*_variable.value(), *varType);
|
||||
}
|
||||
if (_variable.isConstant())
|
||||
{
|
||||
if (!_variable.type()->isValueType())
|
||||
|
@ -0,0 +1,10 @@
|
||||
contract D {
|
||||
mapping (uint => uint) a;
|
||||
mapping (uint => uint) b;
|
||||
function foo() public view {
|
||||
mapping (uint => uint) storage c = b;
|
||||
b = c;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (160-161): Mappings cannot be assigned to.
|
@ -0,0 +1,27 @@
|
||||
contract C {
|
||||
mapping (uint => address payable [ ]) public a = a ;
|
||||
}
|
||||
|
||||
contract D {
|
||||
mapping (uint => uint) a;
|
||||
mapping (uint => uint) b = a;
|
||||
}
|
||||
|
||||
contract F {
|
||||
mapping (uint => uint) a;
|
||||
mapping (uint => uint) b;
|
||||
|
||||
function foo() public {
|
||||
a = b;
|
||||
}
|
||||
}
|
||||
|
||||
contract G {
|
||||
uint x = 1;
|
||||
mapping (uint => uint) b = x;
|
||||
}
|
||||
// ----
|
||||
// TypeError: (17-67): Mappings cannot be assigned to.
|
||||
// TypeError: (120-148): Mappings cannot be assigned to.
|
||||
// TypeError: (263-264): Mappings cannot be assigned to.
|
||||
// TypeError: (312-340): Mappings cannot be assigned to.
|
@ -0,0 +1,8 @@
|
||||
contract D {
|
||||
mapping (uint => uint) a;
|
||||
function foo() public view {
|
||||
mapping (uint => int) storage c = a;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (84-119): Type mapping(uint256 => uint256) is not implicitly convertible to expected type mapping(uint256 => int256).
|
Loading…
Reference in New Issue
Block a user