Solidity – Compile Error: Expected Primary Expression

solidity

I'm trying to compile a contract in the solidity browser compiler
and get this error:

Untitled:19:9: Error: Expected primary expression.

}

^

Is this due to the throw; statement?

contract user {

    address public owner;

    function user(){
        owner = msg.sender;
        }

    function kill(){
        suicide(owner);
    }

    modifier onlyOwner{
        if (msg.sender != owner){
            throw;
        }else{
            -
        }
    }
}

Best Answer

Here's your modified code:

pragma solidity ^0.4.0;

contract user {

    address public owner;

    function user() {
        owner = msg.sender;
    }

    function kill() {
        suicide(owner);
    }

    modifier onlyOwner {
        if (msg.sender != owner) {
            throw;
        } else {
            _;
        }
    }
}

The only problem with your code is that I had to replace your - with a _;. See Are underscores `_` in modifiers code or are they just meant to look cool? for more information on the _ modifiers.

Your modified code then compiles perfectly in the Solidity realtime compiler and runtime:

enter image description here

Related Topic