aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-04-03 22:15:36 +0800
committerGitHub <noreply@github.com>2018-04-03 22:15:36 +0800
commit7753249f646f239819c62ab6847438dc84b6e04b (patch)
treeb209000917d198d897d078c0eb7ecf47d704bf30
parent19f288774112c64331b55aca0f6519452dea2c74 (diff)
parentf9efa417492916546d23115da7a55e86090d47dd (diff)
downloaddexon-solidity-7753249f646f239819c62ab6847438dc84b6e04b.tar.gz
dexon-solidity-7753249f646f239819c62ab6847438dc84b6e04b.tar.zst
dexon-solidity-7753249f646f239819c62ab6847438dc84b6e04b.zip
Merge pull request #3699 from ethereum/interfaceExternalVisibility
Defaults to external visibility for interfaces.
-rw-r--r--libsolidity/analysis/StaticAnalyzer.cpp10
-rw-r--r--libsolidity/analysis/SyntaxChecker.cpp15
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp48
-rw-r--r--test/libsolidity/syntaxTests/visibility/interface/function_default.sol6
-rw-r--r--test/libsolidity/syntaxTests/visibility/interface/function_default050.sol7
-rw-r--r--test/libsolidity/syntaxTests/visibility/interface/function_external050.sol5
-rw-r--r--test/libsolidity/syntaxTests/visibility/interface/function_internal.sol5
-rw-r--r--test/libsolidity/syntaxTests/visibility/interface/function_private.sol5
-rw-r--r--test/libsolidity/syntaxTests/visibility/interface/function_public.sol5
-rw-r--r--test/libsolidity/syntaxTests/visibility/interface/function_public050.sol6
10 files changed, 52 insertions, 60 deletions
diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp
index 6aee260e..d96f8748 100644
--- a/libsolidity/analysis/StaticAnalyzer.cpp
+++ b/libsolidity/analysis/StaticAnalyzer.cpp
@@ -50,6 +50,16 @@ void StaticAnalyzer::endVisit(ContractDefinition const&)
bool StaticAnalyzer::visit(FunctionDefinition const& _function)
{
+ const bool isInterface = m_currentContract->contractKind() == ContractDefinition::ContractKind::Interface;
+
+ if (_function.noVisibilitySpecified())
+ m_errorReporter.warning(
+ _function.location(),
+ "No visibility specified. Defaulting to \"" +
+ Declaration::visibilityToString(_function.visibility()) +
+ "\". " +
+ (isInterface ? "In interfaces it defaults to external." : "")
+ );
if (_function.isImplemented())
m_currentFunction = &_function;
else
diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp
index 3a32810b..b595c4d1 100644
--- a/libsolidity/analysis/SyntaxChecker.cpp
+++ b/libsolidity/analysis/SyntaxChecker.cpp
@@ -214,18 +214,9 @@ bool SyntaxChecker::visit(FunctionDefinition const& _function)
{
bool const v050 = m_sourceUnit->annotation().experimentalFeatures.count(ExperimentalFeature::V050);
- if (_function.noVisibilitySpecified())
- {
- if (v050)
- m_errorReporter.syntaxError(_function.location(), "No visibility specified.");
- else
- m_errorReporter.warning(
- _function.location(),
- "No visibility specified. Defaulting to \"" +
- Declaration::visibilityToString(_function.visibility()) +
- "\"."
- );
- }
+ if (v050 && _function.noVisibilitySpecified())
+ m_errorReporter.syntaxError(_function.location(), "No visibility specified.");
+
return true;
}
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index f18c906d..dcdc1519 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -6429,54 +6429,6 @@ BOOST_AUTO_TEST_CASE(interface_function_bodies)
CHECK_ERROR(text, TypeError, "Functions in interfaces cannot have an implementation");
}
-BOOST_AUTO_TEST_CASE(interface_function_external)
-{
- char const* text = R"(
- pragma experimental "v0.5.0";
- interface I {
- function f() external;
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-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;
- }
- )";
- CHECK_ERROR(text, TypeError, "Functions in interfaces must be declared external.");
-}
-
-BOOST_AUTO_TEST_CASE(interface_function_internal)
-{
- char const* text = R"(
- interface I {
- function f() internal;
- }
- )";
- CHECK_ERROR(text, TypeError, "Functions in interfaces cannot be internal or private.");
-}
-
-BOOST_AUTO_TEST_CASE(interface_function_private)
-{
- char const* text = R"(
- interface I {
- function f() private;
- }
- )";
- CHECK_ERROR(text, TypeError, "Functions in interfaces cannot be internal or private.");
-}
-
BOOST_AUTO_TEST_CASE(interface_events)
{
char const* text = R"(
diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_default.sol b/test/libsolidity/syntaxTests/visibility/interface/function_default.sol
new file mode 100644
index 00000000..7b9044dd
--- /dev/null
+++ b/test/libsolidity/syntaxTests/visibility/interface/function_default.sol
@@ -0,0 +1,6 @@
+interface I {
+ function f();
+}
+// ----
+// Warning: Functions in interfaces should be declared external.
+// Warning: No visibility specified. Defaulting to "public". In interfaces it defaults to external.
diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_default050.sol b/test/libsolidity/syntaxTests/visibility/interface/function_default050.sol
new file mode 100644
index 00000000..127d4e92
--- /dev/null
+++ b/test/libsolidity/syntaxTests/visibility/interface/function_default050.sol
@@ -0,0 +1,7 @@
+pragma experimental "v0.5.0";
+interface I {
+ function f();
+}
+// ----
+// SyntaxError: No visibility specified.
+// TypeError: Functions in interfaces must be declared external.
diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_external050.sol b/test/libsolidity/syntaxTests/visibility/interface/function_external050.sol
new file mode 100644
index 00000000..3f0a9aca
--- /dev/null
+++ b/test/libsolidity/syntaxTests/visibility/interface/function_external050.sol
@@ -0,0 +1,5 @@
+pragma experimental "v0.5.0";
+interface I {
+ function f() external;
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_internal.sol b/test/libsolidity/syntaxTests/visibility/interface/function_internal.sol
new file mode 100644
index 00000000..a1cf5246
--- /dev/null
+++ b/test/libsolidity/syntaxTests/visibility/interface/function_internal.sol
@@ -0,0 +1,5 @@
+interface I {
+ function f() internal;
+}
+// ----
+// TypeError: Functions in interfaces cannot be internal or private.
diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_private.sol b/test/libsolidity/syntaxTests/visibility/interface/function_private.sol
new file mode 100644
index 00000000..887ebd4b
--- /dev/null
+++ b/test/libsolidity/syntaxTests/visibility/interface/function_private.sol
@@ -0,0 +1,5 @@
+interface I {
+ function f() private;
+}
+// ----
+// TypeError: Functions in interfaces cannot be internal or private.
diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_public.sol b/test/libsolidity/syntaxTests/visibility/interface/function_public.sol
new file mode 100644
index 00000000..146d4f5b
--- /dev/null
+++ b/test/libsolidity/syntaxTests/visibility/interface/function_public.sol
@@ -0,0 +1,5 @@
+interface I {
+ function f() public;
+}
+// ----
+// Warning: Functions in interfaces should be declared external. \ No newline at end of file
diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_public050.sol b/test/libsolidity/syntaxTests/visibility/interface/function_public050.sol
new file mode 100644
index 00000000..f957f0b4
--- /dev/null
+++ b/test/libsolidity/syntaxTests/visibility/interface/function_public050.sol
@@ -0,0 +1,6 @@
+pragma experimental "v0.5.0";
+interface I {
+ function f() public;
+}
+// ----
+// TypeError: Functions in interfaces must be declared external. \ No newline at end of file