diff --git a/src/powerquery-language-services/inspection/type/inspectType/common.ts b/src/powerquery-language-services/inspection/type/inspectType/common.ts index c8082af..c6ace5e 100644 --- a/src/powerquery-language-services/inspection/type/inspectType/common.ts +++ b/src/powerquery-language-services/inspection/type/inspectType/common.ts @@ -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) { diff --git a/src/test/inspection/type.ts b/src/test/inspection/type.ts index 4af5a5e..41b5ead 100644 --- a/src/test/inspection/type.ts +++ b/src/test/inspection/type.ts @@ -111,6 +111,23 @@ describe(`Inspection - Type`, () => { TypeUtils.numberLiteral(false, `1`), ), )); + + it(`each _`, async () => + await assertEqualRootType( + `each _`, + TypeUtils.definedFunction( + false, + [ + { + isNullable: false, + isOptional: false, + type: Type.TypeKind.Any, + nameLiteral: `_`, + }, + ], + Type.UnknownInstance, + ), + )); }); describe(`${Ast.NodeKind.ErrorHandlingExpression}`, () => { @@ -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}`, () => {