diff options
author | chriseth <chris@ethereum.org> | 2018-02-01 20:54:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-01 20:54:51 +0800 |
commit | 07f8f96c94cd2a2602226dee2aa08597c1bd21d6 (patch) | |
tree | b3a2872738768ae7fdbf4190b2587b206a21f936 | |
parent | cc1c461fc05255f0efc3a36f6c90336092c66aae (diff) | |
parent | b545987ec7916209f0a1dfe196d78b49cdf2ddae (diff) | |
download | dexon-solidity-07f8f96c94cd2a2602226dee2aa08597c1bd21d6.tar.gz dexon-solidity-07f8f96c94cd2a2602226dee2aa08597c1bd21d6.tar.zst dexon-solidity-07f8f96c94cd2a2602226dee2aa08597c1bd21d6.zip |
Merge pull request #3450 from ethereum/interface-public-visibility
Issue warning for using public visibility for interface functions
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 2 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 8 | ||||
-rw-r--r-- | test/libsolidity/ViewPureChecker.cpp | 4 |
4 files changed, 12 insertions, 3 deletions
diff --git a/Changelog.md b/Changelog.md index 4909aca3..3a1a23dc 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ Features: * Inline Assembly: Support some restricted tokens (return, byte, address) as identifiers in Julia mode. * SMT Checker: If-else branch conditions are taken into account in the SMT encoding of the program variables. + * Type Checker: Issue warning for using ``public`` visibility for interface functions. Bugfixes: * Parser: Disallow event declarations with no parameter list. diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 191f78e9..d67142e4 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -604,6 +604,8 @@ bool TypeChecker::visit(FunctionDefinition const& _function) { if (_function.visibility() < FunctionDefinition::Visibility::Public) m_errorReporter.typeError(_function.location(), "Functions in interfaces cannot be internal or private."); + else if (_function.visibility() != FunctionDefinition::Visibility::External) + m_errorReporter.warning(_function.location(), "Functions in interfaces should be declared external."); } if (_function.isConstructor()) m_errorReporter.typeError(_function.location(), "Constructor cannot be defined in interfaces."); diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index eb6a440e..513b5e2c 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -5963,6 +5963,12 @@ BOOST_AUTO_TEST_CASE(interface_function_external) BOOST_AUTO_TEST_CASE(interface_function_public) { char const* text = R"( + interface I { + function f() public; + } + )"; + CHECK_WARNING(text, "Functions in interfaces should be declared external."); + text = R"( pragma experimental "v0.5.0"; interface I { function f() public; @@ -6306,7 +6312,7 @@ BOOST_AUTO_TEST_CASE(no_unused_warning_interface_arguments) { char const* text = R"( interface I { - function f(uint a) pure public returns (uint b); + function f(uint a) pure external returns (uint b); } )"; CHECK_SUCCESS_NO_WARNINGS(text); diff --git a/test/libsolidity/ViewPureChecker.cpp b/test/libsolidity/ViewPureChecker.cpp index 6353ae8a..debeb4dc 100644 --- a/test/libsolidity/ViewPureChecker.cpp +++ b/test/libsolidity/ViewPureChecker.cpp @@ -181,10 +181,10 @@ BOOST_AUTO_TEST_CASE(interface) { string text = R"( interface D { - function f() view public; + function f() view external; } contract C is D { - function f() view public {} + function f() view external {} } )"; CHECK_SUCCESS_NO_WARNINGS(text); |