0

Maybe this is really obvious but for some reason I can't shake this error. At compile I get the following error:

TypeError: Indexed expression has to be a type, mapping or array (is uint256)
        voteType[msg.sender] = 2;
        ^------^
Compilation failed. See above.

The indexed expression is a mapping to a type (uint) which should be all good.

Relevant code:

function castVote (uint voteType) canVote {
//        require (voteType[msg.sender] == 0);
        if (voteType == 2) {//2 here meaning "Real" account.
        count[upForVote].voteReal++;
        voteType[msg.sender] = 2;
        }
        if (voteType == 1) {//1 here meaning "Fake" acount.
        count[upForVote].voteFake++;
        voteType[msg.sender] = 1;
        }
        voteInProgress[msg.sender] = true;
    }
  • Can you add declaration of voteType please? – Roman Frolov Jan 30 '18 at 1:04
1

Your function accepts a parameter called voteType, and it's a uint. So you can't index into it, because it's not an array or a mapping.

My guess is that elsewhere you declared a state variable also called voteType, but it's being shadowed by the parameter name in this function.

One convention in these cases is to use a leading underscore to differentiate, although that's usually for the case where both variables have the same type:

function castVote (uint _voteType) canVote {
    if (_voteType == 2) {  //2 here meaning "Real" account.
        count[upForVote].voteReal++;
        voteType[msg.sender] = 2;
    }
    if (_voteType == 1) {  //1 here meaning "Fake" acount.
        count[upForVote].voteFake++;
        voteType[msg.sender] = 1;
    }
    voteInProgress[msg.sender] = true;
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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