0

I am getting a syntax error in my sol contract, but I have rechecked the syntax and everything looks fine to me. So any help would be appreciated. This is my code:

pragma experimental ABIEncoderV2;
pragma solodity >= 0.6.0 < 0.9.0;

contract Record {

    struct MedRecord {
        string password;
        string name;
        address patient;
        address[] doctor;
    }
    mapping(address => MedRecord) internal medRecords;

    address[] public recordList;


    function addRecord(address _key, string memory password, string memory name) public {
        address docs[] = new; ////////////////////////ERROR LINE////////////////////
        medRecords[_key] = MedRecord(password, name, _key, []);
        recordList.push(_key);
    }

    function remove(address _key) public {
        delete medRecords[_key];
    }
    
    // function contains(address _key) public view returns (bool) {
    //     return MedRecords[_key][0] != '';
    // }
    
    function getByKey(address _key) public view returns (MedRecord memory) {
        return medRecords[_key];
    }
}

My error Message: enter image description here

2 Answers 2

0

This would be the correct code:

pragma experimental ABIEncoderV2;
pragma solidity >= 0.6.0 < 0.9.0; // typo fixed here.

contract Record {

    struct MedRecord {
        string password;
        string name;
        address patient;
        address[] doctor;
    }
    mapping(address => MedRecord) internal medRecords;

    address[] public recordList;


    function addRecord(address _key, string memory password, string memory name) public {
        address[] memory docs; // needs to be completed with the array of addresses you'd like.
        medRecords[_key] = MedRecord(password, name, _key, docs);
        recordList.push(_key);
    }

    function remove(address _key) public {
        delete medRecords[_key];
    }
    
    // function contains(address _key) public view returns (bool) {
    //     return MedRecords[_key][0] != '';
    // }
    
    function getByKey(address _key) public view returns (MedRecord memory) {
        return medRecords[_key];
    }
}

0

If you want to create an array for address then use brackets after address not after variable. Do it like

address[] memory docs;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.