4

From the docs:

contract test {
    enum ActionChoices { GoLeft, GoRight, GoStraight, SitStill }
    ActionChoices choice;
    ...

Line 2 deliberately omits a ;.

Attempting to compile the snippet but with a ; gives the following error:

ParserError: Function, variable, struct or modifier declaration expected.

Why is it that these enum declaration statements require there to not have a semicolon?

1 Answer 1

5

I guess the compiler uses the semicolon ; and curly brackets {} to determine the scope of the code it's applied too. This is necessary for the compilation process to know what instructions belong where and when they should be executed.

The semicolon determines the end of single instructions or declarations. The curly brackets determine the the start and end of arbitrary numbers of instructions or delcarations, like functions, modifiers, structs, enums and the contract itself.

So in the case of the enum I suppose it doesn't need you to specify when the end of the declaration is with a semicolon because it knows from the closing curly bracket.

1
  • Ah I see, so it's more like an if or for statement.
    – Daniel Que
    Jan 28, 2018 at 10:17

Your Answer

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

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