From 042ccd24ab43396d1144abcbe438e74a7c7d9143 Mon Sep 17 00:00:00 2001 From: hrkrshnn Date: Fri, 3 Apr 2020 13:26:57 +0530 Subject: [PATCH 1/3] Added error message for virtual (library) functions; test case --- libsolidity/analysis/TypeChecker.cpp | 2 ++ .../syntaxTests/inheritance/virtual/library_err.sol | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 test/libsolidity/syntaxTests/inheritance/virtual/library_err.sol 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/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". From 35a743e2224f1da14566dae331c16bb9056ca10b Mon Sep 17 00:00:00 2001 From: hrkrshnn Date: Fri, 3 Apr 2020 15:11:22 +0530 Subject: [PATCH 2/3] Added a changelog --- Changelog.md | 1 + 1 file changed, 1 insertion(+) 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) From 7e2cb9b57c59c41ef0383b4133ae1270297360ed Mon Sep 17 00:00:00 2001 From: hrkrshnn Date: Fri, 3 Apr 2020 15:49:50 +0530 Subject: [PATCH 3/3] Removed virtual from a library function in gnosis test --- test/compilationTests/gnosis/Utils/Math.sol | 1 - 1 file changed, 1 deletion(-) 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)