Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Bug fix: Fail inheritance search on bad base node type #2873

Merged
merged 2 commits into from
Mar 9, 2020
Merged
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
18 changes: 14 additions & 4 deletions packages/codec/lib/abi-data/allocate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,20 @@ function allocateCalldataAndReturndata(
//search through base contracts, from most derived (left) to most base (right)
if (contractNode) {
const linearizedBaseContracts = contractNode.linearizedBaseContracts;
debug("linearized: %O", linearizedBaseContracts);
node = linearizedBaseContracts.reduce(
(foundNode: Ast.AstNode, baseContractId: number) => {
if (foundNode !== undefined) {
return foundNode; //once we've found something, we don't need to keep looking
}
let baseContractNode = referenceDeclarations[baseContractId];
if (baseContractNode === undefined) {
let baseContractNode =
baseContractId === contractNode.id
? contractNode //skip the lookup if we already have the right node! this is to reduce errors from collision
: referenceDeclarations[baseContractId];
if (
baseContractNode === undefined ||
baseContractNode.nodeType !== "ContractDefinition"
) {
return null; //return null rather than undefined so that this will propagate through
//(i.e. by returning null here we give up the search)
//(we don't want to continue due to possibility of grabbing the wrong override)
Expand Down Expand Up @@ -599,7 +606,10 @@ function allocateEvent(
return foundNode; //once we've found something, we don't need to keep looking
}
let baseContractNode = referenceDeclarations[baseContractId];
if (baseContractNode === undefined) {
if (
baseContractNode === undefined ||
baseContractNode.nodeType !== "ContractDefinition"
) {
debug("can't find base node, bailing!");
return null; //return null rather than undefined so that this will propagate through
//(i.e. by returning null here we give up the search)
Expand Down Expand Up @@ -980,7 +990,7 @@ export function getEventAllocations(
for (let baseId of linearizedBaseContractsMinusSelf) {
debug("checking base baseId: %d", baseId);
let baseNode = referenceDeclarations[compilationId][baseId];
if (!baseNode) {
if (!baseNode || baseNode.nodeType !== "ContractDefinition") {
debug("failed to find node for baseId: %d", baseId);
break; //not a continue!
//if we can't find the base node, it's better to stop the loop,
Expand Down