Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite recursion for "each _" #244

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ export async function dereferencedIdentifierType(
scopeItem = nodeScope.get(deferencedLiteral.slice(1));
}

if (deferencedLiteral === "_" && scopeItem?.kind === ScopeItemKind.Each) {
return Type.UnknownInstance;
}

// The deferenced identifier can't be resolved within the local scope.
// It either is either an invalid identifier or an external identifier (e.g `Odbc.Database`).
if (scopeItem === undefined) {
Expand Down
20 changes: 20 additions & 0 deletions src/test/inspection/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ describe(`Inspection - Type`, () => {
TypeUtils.numberLiteral(false, `1`),
),
));

it(`each _`, async () =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind adding a test for each [foo] and each _[foo] to cover field access as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'm not going to block this PR on that. I'll do a follow-up change.

await assertEqualRootType(
`each _`,
TypeUtils.definedFunction(
false,
[
{
isNullable: false,
isOptional: false,
type: Type.TypeKind.Any,
nameLiteral: `_`,
},
],
Type.UnknownInstance,
),
));
});

describe(`${Ast.NodeKind.ErrorHandlingExpression}`, () => {
Expand Down Expand Up @@ -367,6 +384,9 @@ describe(`Inspection - Type`, () => {

it(`let x = 1 in x`, async () =>
await assertEqualRootType(`let x = 1 in x`, TypeUtils.numberLiteral(false, `1`)));

it(`let _ = 1 in 1`, async () =>
await assertEqualRootType(`let _ = 1 in 1`, TypeUtils.numberLiteral(false, `1`)));
});

describe(`${Ast.NodeKind.IfExpression}`, () => {
Expand Down