Error: Expected token LBRACE in AlethZero

SilentCiceroSilentCicero Toronto, CAMember Posts: 159 ✭✭✭
edited January 2015 in Solidity
I get this error ":4:33: Error: Expected token LBRACE" when using the 'constant' term before declaring return.

For example:
contract NameReg{
function register(string32 _){}
function unregister(){}
function addressOf(string32 _) constant returns(address _){} // Such as here <<
function nameOf(address _) constant returns(string32 _){} // And here <<
function kill(){}
}

Once the constant is removed the Solidity Error goes away.

I'm using Ubuntu 14.04 x64, AlethZero PoC7 built from latest CPP-Ethereum. I also get the same error on my Windows copy.

Comments

  • BitcoinzieBitcoinzie Member Posts: 73 ✭✭
    edited January 2015
    Declaration error: Identifier already declared.
    function addressOf(string32 _) constant returns(address _){} // Such as here <<
                                                    ^-------^
    That's the error I get when trying to compile your contract...
  • SilentCiceroSilentCicero Toronto, CAMember Posts: 159 ✭✭✭
    edited January 2015
    Strange, but is the code inherently incorrect? I copied a part of that code from this example posted by Gaven.

    https://github.com/ethereum/dapp-bin/blob/master/namereg/namereg.sol

    Do you think it is my build, or something else? I'll do a new build now and see what happens.
  • BitcoinzieBitcoinzie Member Posts: 73 ✭✭
    I'm using the online compiler located at https://chriseth.github.io/cpp-ethereum/
  • SilentCiceroSilentCicero Toronto, CAMember Posts: 159 ✭✭✭
    edited January 2015
    Yeah, I just used that compiler as well. Same error as you. Any solution to this?

    It seems as though, when I remove the underscores and replace the var with a different name like a letter, the error goes away.

    This function as provided by the online compiler works fine:
    "function addressOf(string32 name) constant returns (address addr) {}"

    However this function provided in the comments section of Gav's namereg.sol example, does not:
    "function addressOf(string32 _) constant returns(address _){}"

    I'll just try and avoid using "_"'s as var names. I think because "_" interferes with the constant flag.
  • BitcoinzieBitcoinzie Member Posts: 73 ✭✭
    That's it exactly.. In general you shouldn't use special characters, unless like this "var_xx = whatever". I'll use it where I have repetition in variables so it'd be like var_1, var_2 ... Avoid using special characters alone.
  • chrisethchriseth Member Posts: 170 ✭✭✭
    '_' is a perfectly fine character for a variable name. The problem is that you use the same for both the argument and the return parameter, so you end up with two local variables of the same name, which is not possible.
    Note that in the original example, the return parameter is "__", so a double underscore.
  • BitcoinzieBitcoinzie Member Posts: 73 ✭✭
    That's why I try to avoid using things like just "_" a quick glance and you can easily mistake "_" for "__".
Sign In or Register to comment.