Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libsolidity/analysis/DocStringTagParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void DocStringTagParser::parseDocStrings(
if (!_node.documentation())
return;

_annotation.docTags = DocStringParser{*_node.documentation(), m_errorReporter}.parse();
_annotation.docTags = DocStringParser{*_node.documentation(), m_errorReporter, _validTags}.parse();

for (auto const& [tagName, tagValue]: _annotation.docTags)
{
Expand Down
12 changes: 8 additions & 4 deletions libsolidity/parsing/DocStringParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,17 @@ std::multimap<std::string, DocTag> DocStringParser::parse()
currPos = parseDocTagLine(currPos, end, true);
else if (currPos != end)
{
// if it begins without a tag then consider it as @notice
// if it begins without a tag then consider it as @notice (only if @notice is valid for this node type)
if (currPos == m_node.text()->begin())
{
currPos = parseDocTag(currPos, end, "notice");
continue;
if (m_validTags.empty() || m_validTags.count("notice"))
{
currPos = parseDocTag(currPos, end, "notice");
continue;
}
// If notice is not valid, fall through to skip this line
}
else if (nlPos == end) //end of text
if (nlPos == end) //end of text
break;
// else skip the line if a newline was found and we get here
currPos = nlPos + 1;
Expand Down
12 changes: 10 additions & 2 deletions libsolidity/parsing/DocStringParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <libsolidity/ast/ASTAnnotations.h>
#include <liblangutil/SourceLocation.h>
#include <set>
#include <string>

namespace solidity::langutil
Expand All @@ -41,9 +42,15 @@ class DocStringParser
{
public:
/// @param _documentedNode the node whose documentation is parsed.
DocStringParser(StructuredDocumentation const& _documentedNode, langutil::ErrorReporter& _errorReporter):
/// @param _validTags set of valid tags for this node type (used to determine if implicit @notice should be added).
DocStringParser(
StructuredDocumentation const& _documentedNode,
langutil::ErrorReporter& _errorReporter,
std::set<std::string> const& _validTags = {}
):
m_node(_documentedNode),
m_errorReporter(_errorReporter)
m_errorReporter(_errorReporter),
m_validTags(_validTags)
{}
std::multimap<std::string, DocTag> parse();

Expand All @@ -62,6 +69,7 @@ class DocStringParser

StructuredDocumentation const& m_node;
langutil::ErrorReporter& m_errorReporter;
std::set<std::string> m_validTags;
/// Mapping tag name -> content.
std::multimap<std::string, DocTag> m_docTags;
DocTag* m_lastTag = nullptr;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// Documentation
uint constant x = 8;
// ----
// DocstringParsingError 6546: (0-18): Documentation tag @notice not valid for file-level variables.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* @dev This is a developer note.
*/
uint constant x = 8;
// ----
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @notice This should error.
*/
uint constant x = 8;
// ----
// DocstringParsingError 6546: (0-37): Documentation tag @notice not valid for file-level variables.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* whatever...
*/
uint constant x = 8;
// ----
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Whatever untagged text.
* @dev This should still be parsed.
*/
uint constant x = 8;
// ----