3

Ok I am trying to figure out why Remix IDE is throwing an error saying the

Data location 'memory' must be given.....

for a string argument but the uint arguments don't throw any error?

pragma solidity >=0.4.25 <0.6.0;

contract Monopoly {

string public player1;
uint32 public player2;
uint32 public player3;

    constructor(string memory _player1, uint32 _player2, uint32 _player3) public {
    player1 = _player1;
    player2 = _player2;
    player3 = _player3;
    }
}
Aniket
  • 3,545
  • 2
  • 20
  • 42
user46230
  • 85
  • 1
  • 3
  • Also wondering why solc suddenly started doing this - it seems to apply to all array arguments (solidity strings are a special syntax for an array), so it'll also raise the warning for a uint[] parameter, but not a uint. This seems to apply to all functions, not just the constructor. – Edmund Edgar Dec 14 '18 at 04:48
  • may this answer will helpful for you. check https://ethereum.stackexchange.com/questions/1701/what-does-the-keyword-memory-do-exactly – Mahesh Rajput Dec 14 '18 at 04:58

1 Answers1

3

Have a look here: https://solidity.readthedocs.io/en/latest/050-breaking-changes.html#explicitness-requirements

Explicit data location for all variables of struct, array or mapping types is now mandatory. This is also applied to function parameters and return variables. For example, change uint[] x = m_x to uint[] storage x = m_x, and function f(uint[][] x) to function f(uint[][] memory x) where memory is the data location and might be replaced by storage or calldata accordingly. Note that external functions require parameters with a data location of calldata.

string is a specific type of array, so this logic applies.

This sort of issue, and the possibility such things might pop up in the future is one reason I incline to specific versions in pragma instead of ranges. That way if you switched compilers (possibly without being aware of it) you wouldn't get new and weird issues - just a complaint about the compiler version.

Hope it helps.

Rob Hitchens
  • 55,151
  • 11
  • 89
  • 145
  • So to avoid declaring an explicit data location is it better to use bytes32? – user46230 Dec 14 '18 at 15:21
  • I'm not sure the jssue is worth avoiding, but ways use bytes32 over bytes or string if you can to reduce storage and gas cost. It doesnt need a length param so more efficient. – Rob Hitchens Dec 14 '18 at 16:10