diff --git a/Changelog.md b/Changelog.md index de4596433..e5822af12 100644 --- a/Changelog.md +++ b/Changelog.md @@ -21,6 +21,7 @@ Bugfixes: * Inline Assembly: Fix internal error when accessing incorrect constant variables. * Inheritance: Allow public state variables to override functions with dynamic memory types in their return values. * JSON AST: Always add pointer suffix for memory reference types. + * Type Checker: Disallow virtual for library functions. ### 0.6.4 (2020-03-10) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 1345fbf90..9ddc766b8 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -332,6 +332,8 @@ bool TypeChecker::visit(FunctionDefinition const& _function) m_errorReporter.warning(_function.location(), "Interface functions are implicitly \"virtual\""); if (_function.visibility() == Visibility::Private) m_errorReporter.typeError(_function.location(), "\"virtual\" and \"private\" cannot be used together."); + if (isLibraryFunction) + m_errorReporter.typeError(_function.location(), "Library functions cannot be \"virtual\"."); } if (_function.isPayable()) diff --git a/test/compilationTests/gnosis/Utils/Math.sol b/test/compilationTests/gnosis/Utils/Math.sol index 93e2375c2..090c935ec 100644 --- a/test/compilationTests/gnosis/Utils/Math.sol +++ b/test/compilationTests/gnosis/Utils/Math.sol @@ -177,7 +177,6 @@ library Math { /// @param nums Numbers to look through /// @return max Maximum number function max(int[] memory nums) - virtual public pure returns (int max) diff --git a/test/libsolidity/syntaxTests/inheritance/virtual/library_err.sol b/test/libsolidity/syntaxTests/inheritance/virtual/library_err.sol new file mode 100644 index 000000000..627be82ff --- /dev/null +++ b/test/libsolidity/syntaxTests/inheritance/virtual/library_err.sol @@ -0,0 +1,5 @@ +library L { + function f() internal pure virtual returns (uint) { return 0; } +} +// ---- +// TypeError: (16-79): Library functions cannot be "virtual".