Skip to content

Commit

Permalink
Update natspec comments on state variables.
Browse files Browse the repository at this point in the history
- changing some warnings to errors
  • Loading branch information
aarlt committed Apr 22, 2020
1 parent 136f24a commit a1d681d
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 27 deletions.
12 changes: 3 additions & 9 deletions libsolidity/analysis/DocStringAnalyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,12 @@ bool DocStringAnalyser::visit(VariableDeclaration const& _variable)
{
if (_variable.isStateVariable())
{
static set<string> const validPublicTags = set<string>{"dev", "notice", "title", "author"};
static set<string> const validPublicTags = set<string>{"notice", "dev"};
static set<string> const validNonPublicTags = set<string>{"dev"};
if (_variable.isPublic())
parseDocStrings(_variable, _variable.annotation(), validPublicTags, "public state variables");
else
{
parseDocStrings(_variable, _variable.annotation(), validPublicTags, "non-public state variables");
if (_variable.annotation().docTags.find("notice") != _variable.annotation().docTags.end())
m_errorReporter.warning(_variable.documentation()->location(), "Documentation tag on non-public state variables will be disallowed in 0.7.0. You will need to use the @dev tag explicitly.");
}
if (_variable.annotation().docTags.find("title") != _variable.annotation().docTags.end() ||
_variable.annotation().docTags.find("author") != _variable.annotation().docTags.end())
m_errorReporter.warning(_variable.documentation()->location(), "Documentation tag @title and @author is only allowed on contract definitions. It will be disallowed in 0.7.0.");
parseDocStrings(_variable, _variable.annotation(), validNonPublicTags, "non-public state variables");
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/parsing/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ ASTPointer<VariableDeclaration> Parser::parseVariableDeclaration(
}

if (!_options.isStateVariable && documentation != nullptr)
parserWarning("Only state variables can retrieve a docstring. This will be disallowed in 0.7.0.");
parserError("Only state variables can retrieve a docstring.");

if (dynamic_cast<FunctionTypeName*>(type.get()) && _options.isStateVariable && m_scanner->currentToken() == Token::LBrace)
fatalParserError(
Expand Down
12 changes: 6 additions & 6 deletions test/compilationTests/corion/premium.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ contract thirdPartyPContractAbstract {

contract ptokenDB is tokenDB {}

/**
*
* @title Corion Platform Premium Token
* @author iFA @ Corion Platform
*
*/
contract premium is module, safeMath {
function replaceModule(address payable addr) external override returns (bool success) {
require( super.isModuleHandler(msg.sender) );
Expand All @@ -23,12 +29,6 @@ contract premium is module, safeMath {
require( _success && _active );
_;
}
/**
*
* @title Corion Platform Premium Token
* @author iFA @ Corion Platform
*
*/

string public name = "Corion Premium";
string public symbol = "CORP";
Expand Down
13 changes: 7 additions & 6 deletions test/compilationTests/corion/token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ contract thirdPartyContractAbstract {
function approvedCorionToken(address, uint256, bytes calldata) external returns (bool) {}
}

/**
*
* @title Corion Platform Token
* @author iFA @ Corion Platform
*
*/
contract token is safeMath, module, announcementTypes {
/*
module callbacks
Expand All @@ -26,12 +32,7 @@ contract token is safeMath, module, announcementTypes {
require( _success && _active );
_;
}
/**
*
* @title Corion Platform Token
* @author iFA @ Corion Platform
*
*/

string public name = "Corion";
string public symbol = "COR";
uint8 public decimals = 6;
Expand Down
2 changes: 1 addition & 1 deletion test/externalTests/colony.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function colony_test
FORCE_ABIv2=false
CONFIG="truffle.js"

truffle_setup https:/erak/colonyNetwork.git develop_060
truffle_setup https:/aarlt/colonyNetwork.git natspec_on_state_variables
run_install install_fn

cd lib
Expand Down
2 changes: 1 addition & 1 deletion test/externalTests/zeppelin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function zeppelin_test
OPTIMIZER_LEVEL=1
CONFIG="truffle-config.js"

truffle_setup https:/erak/openzeppelin-contracts.git master_060
truffle_setup https:/aarlt/openzeppelin-contracts.git master
run_install install_fn

truffle_run_test compile_fn test_fn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ contract C {
uint private state;
}
// ----
// Warning: (17-56): Documentation tag @title and @author is only allowed on contract definitions. It will be disallowed in 0.7.0.
// DocstringParsingError: (17-56): Documentation tag @author not valid for non-public state variables.
// DocstringParsingError: (17-56): Documentation tag @title not valid for non-public state variables.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ contract C {
uint private state;
}
// ----
// Warning: (17-74): Documentation tag on non-public state variables will be disallowed in 0.7.0. You will need to use the @dev tag explicitly.
// DocstringParsingError: (17-74): Documentation tag @notice not valid for non-public state variables.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ contract C {
/// @dev example of dev
uint public state;
}
// ----
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ contract C {
}
}
// ----
// Warning: (290-295): Only state variables can retrieve a docstring. This will be disallowed in 0.7.0.
// ParserError: (290-295): Only state variables can retrieve a docstring.

0 comments on commit a1d681d

Please sign in to comment.