From ddd9a8414105dfea4f5bf9d7f028cf047be565f6 Mon Sep 17 00:00:00 2001 From: mejsiej <93134155+mejsiej@users.noreply.github.com> Date: Thu, 2 Dec 2021 12:36:04 +0100 Subject: [PATCH] Improve failure message when generating getter. --- libsolidity/analysis/TypeChecker.cpp | 9 ++++++++- .../070_struct_accessor_one_array_only.sol | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index aacd233a2..d6c589f75 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -592,7 +592,14 @@ bool TypeChecker::visit(VariableDeclaration const& _variable) ); } if (!getter.interfaceFunctionType()) - m_errorReporter.typeError(6744_error, _variable.location(), "Internal or recursive type is not allowed for public state variables."); + { + solAssert(getter.returnParameterNames().size() == getter.returnParameterTypes().size()); + solAssert(getter.parameterNames().size() == getter.parameterTypes().size()); + if (getter.returnParameterTypes().empty() && getter.parameterTypes().empty()) + m_errorReporter.typeError(5359_error, _variable.location(), "The struct has all its members omitted, therefore the getter cannot return any values."); + else + m_errorReporter.typeError(6744_error, _variable.location(), "Internal or recursive type is not allowed for public state variables."); + } } bool isStructMemberDeclaration = dynamic_cast(_variable.scope()) != nullptr; diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/070_struct_accessor_one_array_only.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/070_struct_accessor_one_array_only.sol index 71129da5f..79e7f17fc 100644 --- a/test/libsolidity/syntaxTests/nameAndTypeResolution/070_struct_accessor_one_array_only.sol +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/070_struct_accessor_one_array_only.sol @@ -3,4 +3,4 @@ contract test { Data public data; } // ---- -// TypeError 6744: (58-74): Internal or recursive type is not allowed for public state variables. +// TypeError 5359: (58-74): The struct has all its members omitted, therefore the getter cannot return any values.