Skip to main content
4 of 5
deleted 16 characters in body
Jatago
  • 226
  • 1
  • 7

Since Firstname is a string literal defined in the function scope, missing to explicitly define the data location sets it to storage by default (where the state variables are persisted) [1]. That assignment operation then looks for the data at the provided location, which in the example is not a valid storage reference. In order to solve the compilation error in the provided example, it is necessary to set the memory keyword, as pointed out by user smarx: string memory Firstname = "Hello";.

The second snippet is valid, as of Solidity version 0.4.25.

Given the provided code snippets, the following would be the aggregated code, to serve as reference (SecondContract.sol):

pragma solidity ^0.4.25;

contract UserRegistration {
    function getUserData(address userAddress) public constant returns(string, uint) {
        string memory Firstname = "Hello";
        uint number=123;
        return( Firstname,number);
    }
}

contract SecondContract {
    function FetchDetail(address userAddress) public constant returns(string,uint ) {
        string memory  data1;
        uint  data2;
        UserRegistration ud=new UserRegistration();
        (data1,data2)= ud.getUserData(userAddress);
        return(data1,data2);
    }
}

Deploying SecondContract and calling FetchDetail function with 0x0000000000000000000000000000000000000000 as argument returns:

uint256 123

[1] https://solidity.readthedocs.io/en/v0.4.25/types.html#data-location

Stay super,

Javier

Jatago
  • 226
  • 1
  • 7