Allow global enum definitions.

This commit is contained in:
Daniel Kirchner 2019-09-02 11:52:51 +02:00
parent fae0e10d26
commit 2b938d703c
8 changed files with 50 additions and 1 deletions

View File

@ -99,8 +99,11 @@ ASTPointer<SourceUnit> Parser::parse(shared_ptr<Scanner> const& _scanner)
case Token::Struct:
nodes.push_back(parseStructDefinition());
break;
case Token::Enum:
nodes.push_back(parseEnumDefinition());
break;
default:
fatalParserError(string("Expected pragma, import directive or contract/interface/library/struct definition."));
fatalParserError(string("Expected pragma, import directive or contract/interface/library/struct/enum definition."));
}
}
solAssert(m_recursionDepth == 0, "");

View File

@ -0,0 +1,7 @@
enum E { A }
contract C {
function f() public pure {
E e = E.A;
e;
}
}

View File

@ -0,0 +1,4 @@
enum E { A }
contract E {}
// ----
// DeclarationError: (13-26): Identifier already declared.

View File

@ -0,0 +1,4 @@
enum E { A }
enum E { A }
// ----
// DeclarationError: (13-25): Identifier already declared.

View File

@ -0,0 +1,10 @@
enum E { A }
contract C {
enum E { A }
function f() public pure {
E e = E.A;
e;
}
}
// ----
// Warning: (30-42): This declaration shadows an existing declaration.

View File

@ -0,0 +1,7 @@
==== Source: a ====
enum E { A }
==== Source: b ====
import "a";
enum E { A }
// ----
// DeclarationError: (b:12-24): Identifier already declared.

View File

@ -0,0 +1,7 @@
==== Source: a ====
enum E { A }
==== Source: b ====
import "a";
contract E { }
// ----
// DeclarationError: (b:12-26): Identifier already declared.

View File

@ -0,0 +1,7 @@
==== Source: a ====
enum E { A }
==== Source: b ====
import "a";
struct E { uint256 a; }
// ----
// DeclarationError: (b:12-35): Identifier already declared.