pragma solidity ^0.6.0;
contract UserCrud{
struct userStruct{
uint userAge;
uint index;
bytes32 userName;
bytes32 userEmail;
}
mapping(address => userStruct) private userStructs;
address[] private userIndex;
function insertUser(
address userAddress,
uint userAge,
bytes32 userName,
bytes32 userEmail) public returns (uint index) {
require(!isUser(userAddress));
userStructs[userAddress].userAge = userAge;
userStructs[userAddress].userName = userName;
userStructs[userAddress].userEmail = userEmail;
userStructs[userAddress].index = userIndex.push(userAddress) - 1; //error in this line
}
I got this code from an article regarding Solidity CRUD and was doing some modifications, but I'm facing an error as follows:
TypeError: Type tuple() is not implicitly convertible to expected type
uint256. userStructs[userAddress].index = userIndex.push(userAddress) – 1;
Best Answer
The problems is that since solc v0.6.0
userIndex.push(userAddress)
no longer return the length as in previous versions.You can fix the code with something like this