'Compilation failed Internal Compiler Error: Stack too deep, try using fewer variables
I am trying to compile the bellow contract and i am getting the error. If i remove the mapping i dont get an error: Compiling using default compiler, solidity version: 0.4.24+commit.e67f0147.Emscripten.clang InternalCompilerError: Stack too deep, try using fewer variables. the contract:
contract MasterContract{
struct Person
{
uint Id;
string FirstName;
string LastName;
string FathersName;
string HomeAdress;
string PhoneNumber;
string Username;
string PersonalEmail;
}
mapping(uint => Person) public person;
uint public personsCount;
function addPerson( string _FirstName, string _LastName, string _FathersName, string _HomeAdress, string _PhoneNumber, string _Username, string _PersonalEmail )
private {
personsCount ++;
persons_fn[patientsCount]=Patient(patientsCount, _FirstName, _LastName, _FathersName, _HomeAdress, _PhoneNumber, _Username, _PersonalEmail);
}
}
Solution 1:[1]
I don't see the error that you are having when I try to compile it. However, I had to change persons_fn
to person
and patientsCount
to personsCount
as they were not declared.
I think you just did some refactoring and forgot to change them.
Otherwise the code compiles successfully in Remix with 0.4.24+commit.e67f0147.Emscripten.clang
Here is the fixed code:
pragma solidity ^0.4.24;
contract MasterContract{
struct Person
{
uint Id;
string FirstName;
string LastName;
string FathersName;
string HomeAdress;
string PhoneNumber;
string Username;
string PersonalEmail;
}
mapping(uint => Person) public person;
uint public personsCount;
function addPerson( string _FirstName, string _LastName, string _FathersName, string _HomeAdress, string _PhoneNumber, string _Username, string _PersonalEmail )
private {
personsCount ++;
person[personsCount]=Person(personsCount, _FirstName, _LastName, _FathersName, _HomeAdress, _PhoneNumber, _Username, _PersonalEmail);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dharman |