@@ -49,7 +49,7 @@ bool DocStringTagParser::parseDocStrings(SourceUnit const& _sourceUnit)
4949
5050bool DocStringTagParser::validateDocStringsUsingTypes (SourceUnit const & _sourceUnit)
5151{
52- auto errorWatcher = m_errorReporter.errorWatcher ();
52+ ErrorReporter::ErrorWatcher errorWatcher = m_errorReporter.errorWatcher ();
5353
5454 SimpleASTVisitor visitReturns (
5555 [](ASTNode const &) { return true ; },
@@ -65,39 +65,41 @@ bool DocStringTagParser::validateDocStringsUsingTypes(SourceUnit const& _sourceU
6565 if (tagName == " return" )
6666 {
6767 returnTagsVisited++;
68+ vector<string> returnParameterNames;
69+
6870 if (auto const * varDecl = dynamic_cast <VariableDeclaration const *>(&_node))
6971 {
70- solAssert (varDecl->isPublic (), " @return is only allowed on public state-variables." );
71- if (returnTagsVisited > 1 )
72- m_errorReporter.docstringParsingError (
73- 5256_error,
74- documentationNode.documentation ()->location (),
75- " Documentation tag \" @" + tagName + " \" is only allowed once on state-variables."
76- );
72+ if (!varDecl->isPublic ())
73+ continue ;
74+
75+ // FunctionType() requires the DeclarationTypeChecker to have run.
76+ returnParameterNames = FunctionType (*varDecl).returnParameterNames ();
7777 }
7878 else if (auto const * function = dynamic_cast <FunctionDefinition const *>(&_node))
79+ returnParameterNames = FunctionType (*function).returnParameterNames ();
80+ else
81+ continue ;
82+
83+ string content = tagValue.content ;
84+ string firstWord = content.substr (0 , content.find_first_of (" \t " ));
85+
86+ if (returnTagsVisited > returnParameterNames.size ())
87+ m_errorReporter.docstringParsingError (
88+ 2604_error,
89+ documentationNode.documentation ()->location (),
90+ " Documentation tag \" @" + tagName + " " + content + " \" " +
91+ " exceeds the number of return parameters."
92+ );
93+ else
7994 {
80- string content = tagValue.content ;
81- string firstWord = content.substr (0 , content.find_first_of (" \t " ));
82-
83- if (returnTagsVisited > function->returnParameters ().size ())
95+ string const & parameter = returnParameterNames.at (returnTagsVisited - 1 );
96+ if (!parameter.empty () && parameter != firstWord)
8497 m_errorReporter.docstringParsingError (
85- 2604_error ,
98+ 5856_error ,
8699 documentationNode.documentation ()->location (),
87- " Documentation tag \" @" + tagName + " " + tagValue. content + " \" " +
88- " exceeds the number of return parameters ."
100+ " Documentation tag \" @" + tagName + " " + content + " \" " +
101+ " does not contain the name of its return parameter ."
89102 );
90- else
91- {
92- auto parameter = function->returnParameters ().at (returnTagsVisited - 1 );
93- if (!parameter->name ().empty () && parameter->name () != firstWord)
94- m_errorReporter.docstringParsingError (
95- 5856_error,
96- documentationNode.documentation ()->location (),
97- " Documentation tag \" @" + tagName + " " + tagValue.content + " \" " +
98- " does not contain the name of its return parameter."
99- );
100- }
101103 }
102104 }
103105 }
0 commit comments