Skip to content

Commit

Permalink
fix identifier not found on explicit imports
Browse files Browse the repository at this point in the history
  • Loading branch information
frangio committed Jun 29, 2023
1 parent 154944e commit e5eb706
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.3.10

- Fix "identifier not found" errors seen when the original source code uses explicit imports.

## 0.3.9

- Do not use fully qualified names for types in generated code unless necessary.
Expand Down
2 changes: 1 addition & 1 deletion contracts/Imported.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import { Imported2 } from './Imported2.sol';

contract NotImported {}

contract Imported /* [TODO] is Imported2 */ {
contract Imported is Imported2 {
function _testNotImported(NotImported ni) internal {}
}
2 changes: 1 addition & 1 deletion contracts/Imported2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ pragma solidity ^0.8.0;
contract NotImported2 {}

contract Imported2 {
function _testNotImported(NotImported2 ni) internal {}
function _testNotImported2(NotImported2 ni) internal {}
}
13 changes: 11 additions & 2 deletions src/core.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ Generated by [AVA](https://avajs.dev).
function $_testNotImported(NotImported ni) external {␊
super._testNotImported(ni);␊
}␊
function $_testNotImported2(NotImported2 ni) external {␊
super._testNotImported2(ni);␊
}␊
receive() external payable {}␊
}␊
Expand Down Expand Up @@ -79,8 +83,8 @@ Generated by [AVA](https://avajs.dev).
constructor() payable {␊
}␊
function $_testNotImported(NotImported2 ni) external {␊
super._testNotImported(ni);␊
function $_testNotImported2(NotImported2 ni) external {␊
super._testNotImported2(ni);␊
}␊
receive() external payable {}␊
Expand Down Expand Up @@ -371,6 +375,7 @@ Generated by [AVA](https://avajs.dev).
import "../contracts/Test.sol";␊
import "../contracts/Imported.sol";␊
import "../contracts/Imported2.sol";␊
contract $Foo is Foo {␊
bytes32 public constant __hh_exposed_bytecode_marker = "hardhat-exposed";␊
Expand Down Expand Up @@ -777,6 +782,10 @@ Generated by [AVA](https://avajs.dev).
function $_testNotImported(NotImported ni) external {␊
super._testNotImported(ni);␊
}␊
function $_testNotImported2(NotImported2 ni) external {␊
super._testNotImported2(ni);␊
}␊
receive() external payable {}␊
}␊
Expand Down
Binary file modified src/core.test.ts.snap
Binary file not shown.
13 changes: 11 additions & 2 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,20 @@ function getExposedContent(ast: SourceUnit, relativizePath: (p: string) => strin
}

const contractPrefix = prefix.replace(/^./, c => c.toUpperCase());
const imports = [ast.absolutePath].concat(

const neededAbsoluteImports = [ast.absolutePath].concat(
[...findAll('ImportDirective', ast)]
.filter(i => i.symbolAliases.length > 0)
.map(i => i.absolutePath),
).map(relativizePath);
[...findAll('ContractDefinition', ast)]
.flatMap(c => c.linearizedBaseContracts.map(p => {
const sourceId = deref('ContractDefinition', p).scope;
return deref('SourceUnit', sourceId).absolutePath;
})),
);

// remove duplicates and relativize
const imports = Array.from(new Set(neededAbsoluteImports), relativizePath);

const rawContent = formatLines(
...spaceBetween(
Expand Down

0 comments on commit e5eb706

Please sign in to comment.