diff --git a/Changelog.md b/Changelog.md index 5aa4eeded..d5ff1204c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -24,6 +24,7 @@ Bugfixes: * Type Checker: Disallow signed literals as exponent in exponentiation operator. * Allow `type(Contract).name` for abstract contracts and interfaces. * Type Checker: Disallow structs containing nested mapping in memory as parameters for library functions. + * Type Checker: Disallow ``using for`` directive inside interfaces. ### 0.7.0 (2020-07-28) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 28f2b4152..19272b924 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -3148,6 +3148,16 @@ void TypeChecker::endVisit(Literal const& _literal) _literal.annotation().isPure = true; } +void TypeChecker::endVisit(UsingForDirective const& _usingFor) +{ + if (m_currentContract->isInterface()) + m_errorReporter.typeError( + 9088_error, + _usingFor.location(), + "The \"using for\" directive is not allowed inside interfaces." + ); +} + bool TypeChecker::contractDependenciesAreCyclic( ContractDefinition const& _contract, std::set const& _seenContracts diff --git a/libsolidity/analysis/TypeChecker.h b/libsolidity/analysis/TypeChecker.h index 87ae1d83c..70041766d 100644 --- a/libsolidity/analysis/TypeChecker.h +++ b/libsolidity/analysis/TypeChecker.h @@ -143,6 +143,7 @@ private: bool visit(Identifier const& _identifier) override; void endVisit(ElementaryTypeNameExpression const& _expr) override; void endVisit(Literal const& _literal) override; + void endVisit(UsingForDirective const& _usingForDirective) override; bool contractDependenciesAreCyclic( ContractDefinition const& _contract, diff --git a/test/libsolidity/syntaxTests/bound/interface_using_for.sol b/test/libsolidity/syntaxTests/bound/interface_using_for.sol new file mode 100644 index 000000000..727ff2c46 --- /dev/null +++ b/test/libsolidity/syntaxTests/bound/interface_using_for.sol @@ -0,0 +1,10 @@ +library L { + function f() public {} +} + +interface I { + using L for int; + function g() external; +} +// ---- +// TypeError 9088: (60-76): The "using for" directive is not allowed inside interfaces.