Skip to content

Commit 4aac4c7

Browse files
timwericameel
authored andcommitted
Add Natspec devdoc inheritance support for events
1 parent ce18ddd commit 4aac4c7

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Language Features:
66
Compiler Features:
77
* Commandline Interface: Return exit code ``2`` on uncaught exceptions.
88
* Commandline Interface: Add `--no-cbor-metadata` that skips CBOR metadata from getting appended at the end of the bytecode.
9+
* Natspec: Add event Natspec inheritance for devdoc.
910
* Standard JSON: Add a boolean field `settings.metadata.appendCBOR` that skips CBOR metadata from getting appended at the end of the bytecode.
1011
* Yul Optimizer: Allow replacing the previously hard-coded cleanup sequence by specifying custom steps after a colon delimiter (``:``) in the sequence string.
1112
* Language Server: Add basic document hover support.

libsolidity/interface/Natspec.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Json::Value Natspec::devDocumentation(ContractDefinition const& _contractDef)
168168
));
169169
}
170170

171-
for (auto const& event: _contractDef.events())
171+
for (auto const& event: _contractDef.definedInterfaceEvents())
172172
if (auto devDoc = devDocumentation(event->annotation().docTags); !devDoc.empty())
173173
doc["events"][event->functionType(true)->externalSignature()] = devDoc;
174174

test/libsolidity/SolidityNatspecJSON.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,64 @@ BOOST_AUTO_TEST_CASE(event)
485485
checkNatspec(sourceCode, "ERC20", userDoc, true);
486486
}
487487

488+
BOOST_AUTO_TEST_CASE(event_inheritance)
489+
{
490+
char const* sourceCode = R"(
491+
contract ERC20 {
492+
/// @notice This event is emitted when a transfer occurs.
493+
/// @param from The source account.
494+
/// @param to The destination account.
495+
/// @param amount The amount.
496+
/// @dev A test case!
497+
event Transfer(address indexed from, address indexed to, uint amount);
498+
}
499+
500+
contract A is ERC20 {
501+
}
502+
503+
contract B is A {
504+
}
505+
)";
506+
507+
char const* devDoc = R"ABCDEF(
508+
{
509+
"events":
510+
{
511+
"Transfer(address,address,uint256)":
512+
{
513+
"details": "A test case!",
514+
"params":
515+
{
516+
"amount": "The amount.",
517+
"from": "The source account.",
518+
"to": "The destination account."
519+
}
520+
}
521+
},
522+
"methods": {}
523+
}
524+
)ABCDEF";
525+
checkNatspec(sourceCode, "ERC20", devDoc, false);
526+
checkNatspec(sourceCode, "A", devDoc, false);
527+
checkNatspec(sourceCode, "B", devDoc, false);
528+
529+
char const* userDoc = R"ABCDEF(
530+
{
531+
"events":
532+
{
533+
"Transfer(address,address,uint256)":
534+
{
535+
"notice": "This event is emitted when a transfer occurs."
536+
}
537+
},
538+
"methods": {}
539+
}
540+
)ABCDEF";
541+
checkNatspec(sourceCode, "ERC20", userDoc, true);
542+
checkNatspec(sourceCode, "A", userDoc, true);
543+
checkNatspec(sourceCode, "B", userDoc, true);
544+
}
545+
488546
BOOST_AUTO_TEST_CASE(dev_desc_after_nl)
489547
{
490548
char const* sourceCode = R"(

0 commit comments

Comments
 (0)