Skip to content

Commit

Permalink
Merged main branch and resolved conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
blitz-1306 committed Nov 10, 2022
2 parents 31e97b3 + c4feb1a commit ece08a4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/ast/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,29 @@ function* lookupInFunctionDefinition(
/**
* Lookup the definition corresponding to `name` in the `Block|UncheckedBlock` `scope`. Yield all matches.
*/
function* lookupInBlock(name: string, scope: Block | UncheckedBlock): Iterable<AnyResolvable> {
for (const node of scope.children) {
if (!(node instanceof VariableDeclarationStatement)) {
continue;
}
function* lookupInBlock(
name: string,
scope: Block | UncheckedBlock,
inference: InferType
): Iterable<AnyResolvable> {
let declarations: VariableDeclaration[];

for (const decl of node.vDeclarations) {
if (decl.name === name) {
yield decl;
}
if (lt(inference.version, "0.5.0")) {
declarations = scope.getChildrenByType(VariableDeclaration);
} else {
declarations = scope.children
.filter((node) => node instanceof VariableDeclarationStatement)
.reduce(
(declarations: VariableDeclaration[], statement) => [
...declarations,
...(statement as VariableDeclarationStatement).vDeclarations
],
[]
);
}
for (const declaration of declarations) {
if (declaration.name === name) {
yield declaration;
}
}
}
Expand Down Expand Up @@ -325,7 +338,7 @@ function lookupInScope(
} else if (scope instanceof VariableDeclarationStatement) {
results = scope.vDeclarations.filter((decl) => decl.name === name);
} else if (scope instanceof Block || scope instanceof UncheckedBlock) {
results = lookupInBlock(name, scope);
results = lookupInBlock(name, scope, inference);
} else if (scope instanceof TryCatchClause) {
results = scope.vParameters
? scope.vParameters.vParameters.filter((param) => param.name === name)
Expand Down
22 changes: 22 additions & 0 deletions test/samples/solidity/resolving/block_04.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,27 @@ contract Foo {
foo memory m = foo(bar);

uint bar = m.x;

uint m1 = k;
{uint k;}
}

uint256 x1;
uint256 x2;
uint256 x3;
uint256 x4;

function second() internal {
{
uint256 x1 = 1;
if (x1 > 0) {
uint256 x2 = 2;
}
{
uint256 x3 = 3;
}
}
for (uint256 x4; x4 < 10; x4++) {}
uint256 y = x1 + x2 + x3 + x4;
}
}
19 changes: 19 additions & 0 deletions test/samples/solidity/resolving/block_05.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,23 @@ contract Foo {

foo = 2;
}

uint256 x1;
uint256 x2;
uint256 x3;
uint256 x4;

function second() internal {
{
uint256 x1 = 1;
if (x1 > 0) {
uint256 x2 = 2;
}
{
uint256 x3 = 3;
}
}
for (uint256 x4; x4 < 10; x4++) {}
uint256 y = x1 + x2 + x3 + x4;
}
}

0 comments on commit ece08a4

Please sign in to comment.