Skip to content

Commit 6554f5f

Browse files
committed
Look through instantiation when reusing a parameter name
Instantiating a signature copies a parameter unless the parameter's type has already been resolved, so whether the parameter in a signature's printed scope is the declared one depends on what was checked before. Both name the same declaration, so treating only the declared one as the same reference made printing a reused annotation depend on check order.
1 parent 0cc0c81 commit 6554f5f

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎tsc/internal/checker/nodecopy.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,10 @@ func getExistingNodeTreeVisitor(b *NodeBuilderImpl, bound *recoveryBoundary) *as
354354
symAtLocation == b.ch.unknownSymbol ||
355355
// If the symbol is not found, but was not found in the original scope either we probably have an error, don't reuse the node
356356
(symAtLocation == nil && sym != nil) ||
357-
// If the symbol is found both in declaration scope and in current scope then it should point to the same reference
358-
(symAtLocation != nil && sym != nil && b.ch.getSymbolIfSameReference(b.ch.getExportSymbolOfValueSymbolIfExported(symAtLocation), sym) == nil) {
357+
// If the symbol is found both in declaration scope and in current scope then it should point to the same reference.
358+
// A parameter in scope may be an instantiation of the one in the declaration, depending on whether
359+
// its type was resolved before its signature was instantiated, so compare what they instantiate.
360+
(symAtLocation != nil && sym != nil && b.ch.getSymbolIfSameReference(b.ch.getTargetSymbol(b.ch.getExportSymbolOfValueSymbolIfExported(symAtLocation)), b.ch.getTargetSymbol(sym)) == nil) {
359361
// In isolated declaration we will not do rest parameter expansion so there is no need to report on these.
360362
if symAtLocation != b.ch.unknownSymbol {
361363
b.ctx.tracker.ReportInferenceFallback(node)

‎tsc/testdata/baselines/reference/compiler/checkOrderParameterInTypeQuery(checkorder=isolated).types‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ export class C2 {
3030
}
3131
return new C().test1(this);
3232
>new C().test1(this) : number
33-
>new C().test1 : (a: C2) => number
33+
>new C().test1 : (a: C2) => typeof a.#a
3434
>new C() : C
3535
>C : typeof C
36-
>test1 : (a: C2) => number
36+
>test1 : (a: C2) => typeof a.#a
3737
>this : this
3838
}
3939
}

‎tsc/testdata/baselines/reference/compiler/checkOrderParameterInTypeQuery(checkorder=typesfirst).types‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ export class C2 {
3030
}
3131
return new C().test1(this);
3232
>new C().test1(this) : number
33-
>new C().test1 : (a: C2) => number
33+
>new C().test1 : (a: C2) => typeof a.#a
3434
>new C() : C
3535
>C : typeof C
36-
>test1 : (a: C2) => number
36+
>test1 : (a: C2) => typeof a.#a
3737
>this : this
3838
}
3939
}

0 commit comments

Comments
 (0)