Skip to content

Commit

Permalink
Fix ICE when emitting event from another contract
Browse files Browse the repository at this point in the history
  • Loading branch information
nikola-matic committed Jul 21, 2023
1 parent f466e1e commit 1286081
Show file tree
Hide file tree
Showing 11 changed files with 841 additions and 17 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Compiler Features:


Bugfixes:
* NatSpec: Fix internal error when requesting userdoc or devdoc for a contract that emits an event defined in a foreign contract or interface.


### 0.8.21 (2023-07-19)
Expand Down
17 changes: 0 additions & 17 deletions libsolidity/interface/Natspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,6 @@ Json::Value Natspec::userDocumentation(ContractDefinition const& _contractDef)

for (auto const& event: uniqueInterfaceEvents(_contractDef))
{
ContractDefinition const* eventOrigin = event->annotation().contract;
solAssert(eventOrigin);
solAssert(
*eventOrigin == _contractDef ||
(!eventOrigin->isLibrary() && _contractDef.derivesFrom(*eventOrigin)) ||
(eventOrigin->isLibrary() && !_contractDef.derivesFrom(*eventOrigin))
);

string value = extractDoc(event->annotation().docTags, "notice");
if (!value.empty())
doc["events"][event->functionType(true)->externalSignature()]["notice"] = value;
Expand Down Expand Up @@ -178,16 +170,7 @@ Json::Value Natspec::devDocumentation(ContractDefinition const& _contractDef)

for (auto const& event: uniqueInterfaceEvents(_contractDef))
if (auto devDoc = devDocumentation(event->annotation().docTags); !devDoc.empty())
{
ContractDefinition const* eventOrigin = event->annotation().contract;
solAssert(eventOrigin);
solAssert(
*eventOrigin == _contractDef ||
(!eventOrigin->isLibrary() && _contractDef.derivesFrom(*eventOrigin)) ||
(eventOrigin->isLibrary() && !_contractDef.derivesFrom(*eventOrigin))
);
doc["events"][event->functionType(true)->externalSignature()] = devDoc;
}
for (auto const& error: _contractDef.interfaceErrors())
if (auto devDoc = devDocumentation(error->annotation().docTags); !devDoc.empty())
doc["errors"][error->functionType(true)->externalSignature()].append(devDoc);
Expand Down
112 changes: 112 additions & 0 deletions test/libsolidity/ABIJson/event_emitted_from_foreign_contract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
interface I {
event Event(uint256 value);
}
contract C {
event Event(address indexed sender);
}
contract D {
event Event(address indexed sender);
function test(address sender) public {
emit I.Event(1);
emit C.Event(msg.sender);
emit Event(msg.sender);
}
}
// ----
// :C
// [
// {
// "anonymous": false,
// "inputs":
// [
// {
// "indexed": true,
// "internalType": "address",
// "name": "sender",
// "type": "address"
// }
// ],
// "name": "Event",
// "type": "event"
// }
// ]
//
//
// :D
// [
// {
// "anonymous": false,
// "inputs":
// [
// {
// "indexed": false,
// "internalType": "uint256",
// "name": "value",
// "type": "uint256"
// }
// ],
// "name": "Event",
// "type": "event"
// },
// {
// "anonymous": false,
// "inputs":
// [
// {
// "indexed": true,
// "internalType": "address",
// "name": "sender",
// "type": "address"
// }
// ],
// "name": "Event",
// "type": "event"
// },
// {
// "anonymous": false,
// "inputs":
// [
// {
// "indexed": true,
// "internalType": "address",
// "name": "sender",
// "type": "address"
// }
// ],
// "name": "Event",
// "type": "event"
// },
// {
// "inputs":
// [
// {
// "internalType": "address",
// "name": "sender",
// "type": "address"
// }
// ],
// "name": "test",
// "outputs": [],
// "stateMutability": "nonpayable",
// "type": "function"
// }
// ]
//
//
// :I
// [
// {
// "anonymous": false,
// "inputs":
// [
// {
// "indexed": false,
// "internalType": "uint256",
// "name": "value",
// "type": "uint256"
// }
// ],
// "name": "Event",
// "type": "event"
// }
// ]
Loading

0 comments on commit 1286081

Please sign in to comment.