diff --git a/Changelog.md b/Changelog.md index e6956d5e0..c21f0ae91 100644 --- a/Changelog.md +++ b/Changelog.md @@ -32,6 +32,7 @@ Breaking Changes: * General: Remove assembly instruction aliases ``sha3`` and ``suicide`` * General: C99-style scoping rules are enforced now. This was already the case in the experimental 0.5.0 mode. * General: Disallow combining hex numbers with unit denominations (e.g. ``0x1e wei``). This was already the case in the experimental 0.5.0 mode. + * Name Resolver: Do not exclude public state variables when looking for conflicting declarations. * Optimizer: Remove the no-op ``PUSH1 0 NOT AND`` sequence. * Parser: Disallow trailing dots that are not followed by a number. * Parser: Remove ``constant`` as function state mutability modifer. diff --git a/libsolidity/analysis/DeclarationContainer.cpp b/libsolidity/analysis/DeclarationContainer.cpp index 9e2bf6d31..59a3d5221 100644 --- a/libsolidity/analysis/DeclarationContainer.cpp +++ b/libsolidity/analysis/DeclarationContainer.cpp @@ -49,16 +49,9 @@ Declaration const* DeclarationContainer::conflictingDeclaration( dynamic_cast(&_declaration) ) { - // check that all other declarations with the same name are functions or a public state variable or events. - // And then check that the signatures are different. + // check that all other declarations are of the same kind for (Declaration const* declaration: declarations) { - if (auto variableDeclaration = dynamic_cast(declaration)) - { - if (variableDeclaration->isStateVariable() && !variableDeclaration->isConstant() && variableDeclaration->isPublic()) - continue; - return declaration; - } if ( dynamic_cast(&_declaration) && !dynamic_cast(declaration) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/412_early_exit_on_fatal_errors.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/412_early_exit_on_fatal_errors.sol index 56fc40518..d052dab5d 100644 --- a/test/libsolidity/syntaxTests/nameAndTypeResolution/412_early_exit_on_fatal_errors.sol +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/412_early_exit_on_fatal_errors.sol @@ -8,4 +8,5 @@ contract C { } } // ---- +// DeclarationError: (150-179): Identifier already declared. // DeclarationError: (114-120): Identifier not found or not unique. diff --git a/test/libsolidity/syntaxTests/scoping/function_state_variable_conflict.sol b/test/libsolidity/syntaxTests/scoping/function_state_variable_conflict.sol new file mode 100644 index 000000000..d717981b9 --- /dev/null +++ b/test/libsolidity/syntaxTests/scoping/function_state_variable_conflict.sol @@ -0,0 +1,6 @@ +contract C { + function f(uint) public pure {} + uint public f = 0; +} +// ---- +// DeclarationError: (53-70): Identifier already declared. diff --git a/test/libsolidity/syntaxTests/scoping/state_variable_function_conflict.sol b/test/libsolidity/syntaxTests/scoping/state_variable_function_conflict.sol new file mode 100644 index 000000000..0c732f7fc --- /dev/null +++ b/test/libsolidity/syntaxTests/scoping/state_variable_function_conflict.sol @@ -0,0 +1,6 @@ +contract C { + uint public f = 0; + function f(uint) public pure {} +} +// ---- +// DeclarationError: (40-71): Identifier already declared. diff --git a/test/libsolidity/syntaxTests/scoping/state_variable_function_conflict_former_crash.sol b/test/libsolidity/syntaxTests/scoping/state_variable_function_conflict_former_crash.sol new file mode 100644 index 000000000..fb9180c69 --- /dev/null +++ b/test/libsolidity/syntaxTests/scoping/state_variable_function_conflict_former_crash.sol @@ -0,0 +1,14 @@ +// This used to crash with some compiler versions. +contract SomeContract { + + uint public balance = 0; + + function balance(uint number) public {} + + function doSomething() public { + balance(3); + } +} +// ---- +// DeclarationError: (106-145): Identifier already declared. +// TypeError: (185-195): Type is not callable