From a20c69e8df295e52165ed3d65a2cba7038031509 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Fri, 14 Jun 2024 06:51:53 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Pick=20PR=20#58514=20(Fixed=20a?= =?UTF-8?q?=20regression=20with=20reporting=20u...)=20into=20release-5.5?= =?UTF-8?q?=20(#58841)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mateusz BurzyƄski --- src/compiler/utilities.ts | 7 ++++-- ...s_potentialPredicateUnusedParam.errors.txt | 10 ++++++++ ...cals_potentialPredicateUnusedParam.symbols | 13 ++++++++++ ...Locals_potentialPredicateUnusedParam.types | 24 +++++++++++++++++++ ...sedLocals_potentialPredicateUnusedParam.ts | 8 +++++++ 5 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/noUnusedLocals_potentialPredicateUnusedParam.errors.txt create mode 100644 tests/baselines/reference/noUnusedLocals_potentialPredicateUnusedParam.symbols create mode 100644 tests/baselines/reference/noUnusedLocals_potentialPredicateUnusedParam.types create mode 100644 tests/cases/compiler/noUnusedLocals_potentialPredicateUnusedParam.ts diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index c7170af2355a4..a16c2a9bb3b00 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -11439,7 +11439,7 @@ export function createNameResolver({ } break; } - if (isSelfReferenceLocation(location)) { + if (isSelfReferenceLocation(location, lastLocation)) { lastSelfReferenceLocation = location; } lastLocation = location; @@ -11573,6 +11573,7 @@ export function createNameResolver({ } type SelfReferenceLocation = + | ParameterDeclaration | FunctionDeclaration | ClassDeclaration | InterfaceDeclaration @@ -11580,8 +11581,10 @@ export function createNameResolver({ | TypeAliasDeclaration | ModuleDeclaration; - function isSelfReferenceLocation(node: Node): node is SelfReferenceLocation { + function isSelfReferenceLocation(node: Node, lastLocation: Node | undefined): node is SelfReferenceLocation { switch (node.kind) { + case SyntaxKind.Parameter: + return !!lastLocation && lastLocation === (node as ParameterDeclaration).name; case SyntaxKind.FunctionDeclaration: case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: diff --git a/tests/baselines/reference/noUnusedLocals_potentialPredicateUnusedParam.errors.txt b/tests/baselines/reference/noUnusedLocals_potentialPredicateUnusedParam.errors.txt new file mode 100644 index 0000000000000..929eb5a565a75 --- /dev/null +++ b/tests/baselines/reference/noUnusedLocals_potentialPredicateUnusedParam.errors.txt @@ -0,0 +1,10 @@ +noUnusedLocals_potentialPredicateUnusedParam.ts(1,40): error TS6133: 'a' is declared but its value is never read. + + +==== noUnusedLocals_potentialPredicateUnusedParam.ts (1 errors) ==== + function potentialPredicateUnusedParam(a: unknown) { + ~ +!!! error TS6133: 'a' is declared but its value is never read. + return !!Math.random(); + } + \ No newline at end of file diff --git a/tests/baselines/reference/noUnusedLocals_potentialPredicateUnusedParam.symbols b/tests/baselines/reference/noUnusedLocals_potentialPredicateUnusedParam.symbols new file mode 100644 index 0000000000000..3decedaf23158 --- /dev/null +++ b/tests/baselines/reference/noUnusedLocals_potentialPredicateUnusedParam.symbols @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/noUnusedLocals_potentialPredicateUnusedParam.ts] //// + +=== noUnusedLocals_potentialPredicateUnusedParam.ts === +function potentialPredicateUnusedParam(a: unknown) { +>potentialPredicateUnusedParam : Symbol(potentialPredicateUnusedParam, Decl(noUnusedLocals_potentialPredicateUnusedParam.ts, 0, 0)) +>a : Symbol(a, Decl(noUnusedLocals_potentialPredicateUnusedParam.ts, 0, 39)) + + return !!Math.random(); +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +} + diff --git a/tests/baselines/reference/noUnusedLocals_potentialPredicateUnusedParam.types b/tests/baselines/reference/noUnusedLocals_potentialPredicateUnusedParam.types new file mode 100644 index 0000000000000..090e1ae0fb609 --- /dev/null +++ b/tests/baselines/reference/noUnusedLocals_potentialPredicateUnusedParam.types @@ -0,0 +1,24 @@ +//// [tests/cases/compiler/noUnusedLocals_potentialPredicateUnusedParam.ts] //// + +=== noUnusedLocals_potentialPredicateUnusedParam.ts === +function potentialPredicateUnusedParam(a: unknown) { +>potentialPredicateUnusedParam : (a: unknown) => boolean +> : ^ ^^ ^^^^^^^^^^^^ +>a : unknown +> : ^^^^^^^ + + return !!Math.random(); +>!!Math.random() : boolean +> : ^^^^^^^ +>!Math.random() : boolean +> : ^^^^^^^ +>Math.random() : number +> : ^^^^^^ +>Math.random : () => number +> : ^^^^^^ +>Math : Math +> : ^^^^ +>random : () => number +> : ^^^^^^ +} + diff --git a/tests/cases/compiler/noUnusedLocals_potentialPredicateUnusedParam.ts b/tests/cases/compiler/noUnusedLocals_potentialPredicateUnusedParam.ts new file mode 100644 index 0000000000000..f711939d6d7b9 --- /dev/null +++ b/tests/cases/compiler/noUnusedLocals_potentialPredicateUnusedParam.ts @@ -0,0 +1,8 @@ +// @strict: true +// @noEmit: true +// @noUnusedLocals: true +// @noUnusedParameters: true + +function potentialPredicateUnusedParam(a: unknown) { + return !!Math.random(); +}