returns
with named output parameters introduces new local variable.
E.g. from this question:
contract Test {
address owner;
function Test(){
owner = msg.sender;
}
function getOwner() returns (address owner) {
return owner;
}
}
Here in getOwner
new variable owner
is introduced and initialized to zero. Coincidentally it overrides state variable owner
which leads to unexpected result.
Mappings are only allowed for state variables (or as storage reference types in internal functions).
E.g. from this question:
function getBalance(address addr) returns (uint, uint) {
mapping(address => uint) balancers;
balancers[msg.sender] = 500;
return (balancesA[addr], balancesB[addr]);
}
Here mapping(address => uint) balances
does not allocate new mapping but introduces uninitialized variable. Hence accessing balancers[msg.sender]
is invalid.