Merge pull request #4500 from ethereum/v050-interface-functions-must-be-external

[BREAKING] interface functions must be external
This commit is contained in:
chriseth 2018-07-16 14:43:56 +02:00 committed by GitHub
commit 931794001e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 19 additions and 29 deletions

View File

@ -44,6 +44,7 @@ Breaking Changes:
* Type Checker: Disallow uninitialized storage variables. This was already the case in the experimental 0.5.0 mode. * Type Checker: Disallow uninitialized storage variables. This was already the case in the experimental 0.5.0 mode.
* Type Checker: Only accept a single ``bytes`` type for ``.call()`` (and family), ``keccak256()``, ``sha256()`` and ``ripemd160()``. * Type Checker: Only accept a single ``bytes`` type for ``.call()`` (and family), ``keccak256()``, ``sha256()`` and ``ripemd160()``.
* Type Checker: Fallback function must be external. This was already the case in the experimental 0.5.0 mode. * Type Checker: Fallback function must be external. This was already the case in the experimental 0.5.0 mode.
* Type Checker: Interface functions must be declared external. This was already the case in the experimental 0.5.0 mode.
* Remove obsolete ``std`` directory from the Solidity repository. This means accessing ``https://github.com/ethereum/soldity/blob/develop/std/*.sol`` (or ``https://github.com/ethereum/solidity/std/*.sol`` in Remix) will not be possible. * Remove obsolete ``std`` directory from the Solidity repository. This means accessing ``https://github.com/ethereum/soldity/blob/develop/std/*.sol`` (or ``https://github.com/ethereum/solidity/std/*.sol`` in Remix) will not be possible.
* References Resolver: Turn missing storage locations into an error. This was already the case in the experimental 0.5.0 mode. * References Resolver: Turn missing storage locations into an error. This was already the case in the experimental 0.5.0 mode.
* Syntax Checker: Named return values in function types are an error. * Syntax Checker: Named return values in function types are an error.

View File

@ -1150,6 +1150,7 @@ Interfaces
Interfaces are similar to abstract contracts, but they cannot have any functions implemented. There are further restrictions: Interfaces are similar to abstract contracts, but they cannot have any functions implemented. There are further restrictions:
- Cannot inherit other contracts or interfaces. - Cannot inherit other contracts or interfaces.
- All declared functions must be external.
- Cannot define constructor. - Cannot define constructor.
- Cannot define variables. - Cannot define variables.
- Cannot define structs. - Cannot define structs.
@ -1167,7 +1168,7 @@ Interfaces are denoted by their own keyword:
pragma solidity ^0.4.11; pragma solidity ^0.4.11;
interface Token { interface Token {
function transfer(address recipient, uint amount) public; function transfer(address recipient, uint amount) external;
} }
Contracts can inherit interfaces as they would inherit other contracts. Contracts can inherit interfaces as they would inherit other contracts.

View File

@ -203,7 +203,7 @@ Now someone tricks you into sending ether to the address of this attack wallet:
pragma solidity >0.4.24; pragma solidity >0.4.24;
interface TxUserWallet { interface TxUserWallet {
function transferTo(address dest, uint amount) public; function transferTo(address dest, uint amount) external;
} }
contract TxAttackWallet { contract TxAttackWallet {

View File

@ -671,18 +671,10 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
{ {
if (_function.isImplemented()) if (_function.isImplemented())
m_errorReporter.typeError(_function.location(), "Functions in interfaces cannot have an implementation."); m_errorReporter.typeError(_function.location(), "Functions in interfaces cannot have an implementation.");
if (_function.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050))
{ if (_function.visibility() != FunctionDefinition::Visibility::External)
if (_function.visibility() != FunctionDefinition::Visibility::External) m_errorReporter.typeError(_function.location(), "Functions in interfaces must be declared external.");
m_errorReporter.typeError(_function.location(), "Functions in interfaces must be declared external.");
}
else
{
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()) if (_function.isConstructor())
m_errorReporter.typeError(_function.location(), "Constructor cannot be defined in interfaces."); m_errorReporter.typeError(_function.location(), "Constructor cannot be defined in interfaces.");
} }

View File

@ -11649,7 +11649,7 @@ BOOST_AUTO_TEST_CASE(interface_contract)
char const* sourceCode = R"( char const* sourceCode = R"(
interface I { interface I {
event A(); event A();
function f() public returns (bool); function f() external returns (bool);
function() external payable; function() external payable;
} }

View File

@ -2,6 +2,6 @@ interface I {
constructor() public; constructor() public;
} }
// ---- // ----
// Warning: (15-36): Functions in interfaces should be declared external. // TypeError: (15-36): Functions in interfaces must be declared external.
// TypeError: (15-36): Constructor cannot be defined in interfaces. // TypeError: (15-36): Constructor cannot be defined in interfaces.
// TypeError: (15-36): Constructor must be implemented if declared. // TypeError: (15-36): Constructor must be implemented if declared.

View File

@ -3,6 +3,6 @@ interface I {
} }
// ---- // ----
// Warning: (15-35): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. // Warning: (15-35): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
// Warning: (15-35): Functions in interfaces should be declared external. // TypeError: (15-35): Functions in interfaces must be declared external.
// TypeError: (15-35): Constructor cannot be defined in interfaces. // TypeError: (15-35): Constructor cannot be defined in interfaces.
// TypeError: (15-35): Constructor must be implemented if declared. // TypeError: (15-35): Constructor must be implemented if declared.

View File

@ -1,7 +1,6 @@
interface I { interface I {
function f() public { function f() external pure {
} }
} }
// ---- // ----
// TypeError: (18-45): Functions in interfaces cannot have an implementation. // TypeError: (18-52): Functions in interfaces cannot have an implementation.
// Warning: (18-45): Functions in interfaces should be declared external.

View File

@ -1,5 +1,4 @@
interface I { interface I {
function f(uint a) public returns (bool); function f(uint a) external returns (bool);
} }
// ---- // ----
// Warning: (18-59): Functions in interfaces should be declared external.

View File

@ -1,5 +1,4 @@
interface Interface { interface Interface {
function f() public; function f() external;
} }
// ---- // ----
// Warning: (23-43): Functions in interfaces should be declared external.

View File

@ -2,5 +2,4 @@ interface I {
function f(); function f();
} }
// ---- // ----
// Warning: (15-28): Functions in interfaces should be declared external. // TypeError: (15-28): Functions in interfaces must be declared external.
// Warning: (15-28): No visibility specified. Defaulting to "public". In interfaces it defaults to external.

View File

@ -2,4 +2,4 @@ interface I {
function f() internal; function f() internal;
} }
// ---- // ----
// TypeError: (15-37): Functions in interfaces cannot be internal or private. // TypeError: (15-37): Functions in interfaces must be declared external.

View File

@ -2,4 +2,4 @@ interface I {
function f() private; function f() private;
} }
// ---- // ----
// TypeError: (15-36): Functions in interfaces cannot be internal or private. // TypeError: (15-36): Functions in interfaces must be declared external.

View File

@ -2,4 +2,4 @@ interface I {
function f() public; function f() public;
} }
// ---- // ----
// Warning: (15-35): Functions in interfaces should be declared external. // TypeError: (15-35): Functions in interfaces must be declared external.