Skip to content

Commit 39605ea

Browse files
michaelfigcodex
andcommitted
Emit type queries for inaccessible unique symbol aliases
Preserve const alias identities in declaration output and refresh the unique-symbol declaration baselines. Co-authored-by: Codex <codex@openai.com>
1 parent d91d6e0 commit 39605ea

3 files changed

Lines changed: 36 additions & 28 deletions

File tree

‎tsc/internal/checker/nodebuilderimpl.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,6 +2352,14 @@ func (b *NodeBuilderImpl) serializeTypeForDeclaration(declaration *ast.Declarati
23522352
remove()
23532353
}
23542354
}
2355+
if result == nil {
2356+
if declaration != nil && ast.IsVariableDeclaration(declaration) && t.flags&TypeFlagsUniqueESSymbol != 0 && !b.ch.IsValueSymbolAccessible(t.symbol, b.ctx.enclosingDeclaration) {
2357+
initializer := declaration.Initializer()
2358+
if initializer != nil && ast.IsEntityNameExpression(initializer) {
2359+
result = b.f.NewTypeQueryNode(b.f.DeepCloneNode(initializer), nil)
2360+
}
2361+
}
2362+
}
23552363
if result == nil {
23562364
if reportedInferenceFallback {
23572365
oldSuppress := b.ctx.suppressReportInferenceFallback

‎tsc/testdata/baselines/reference/conformance/uniqueSymbolsDeclarations.js‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,10 @@ declare let letCall: symbol;
415415
declare var varCall: symbol;
416416
declare const constType: unique symbol;
417417
declare const constTypeAndCall: unique symbol;
418-
declare const constInitToConstCall: symbol;
418+
declare const constInitToConstCall: typeof constCall;
419419
declare const constInitToLetCall: symbol;
420420
declare const constInitToVarCall: symbol;
421-
declare const constInitToConstDeclAmbient: symbol;
421+
declare const constInitToConstDeclAmbient: typeof constType;
422422
declare let letInitToConstCall: symbol;
423423
declare let letInitToLetCall: symbol;
424424
declare let letInitToVarCall: symbol;
@@ -452,9 +452,9 @@ declare class C {
452452
readwriteCall: symbol;
453453
}
454454
declare const c: C;
455-
declare const constInitToCReadonlyStaticCall: symbol;
456-
declare const constInitToCReadonlyStaticType: symbol;
457-
declare const constInitToCReadonlyStaticTypeAndCall: symbol;
455+
declare const constInitToCReadonlyStaticCall: typeof C.readonlyStaticCall;
456+
declare const constInitToCReadonlyStaticType: typeof C.readonlyStaticType;
457+
declare const constInitToCReadonlyStaticTypeAndCall: typeof C.readonlyStaticTypeAndCall;
458458
declare const constInitToCReadwriteStaticCall: symbol;
459459
declare const constInitToCReadonlyStaticCallWithTypeQuery: typeof C.readonlyStaticCall;
460460
declare const constInitToCReadonlyStaticTypeWithTypeQuery: typeof C.readonlyStaticType;
@@ -470,7 +470,7 @@ interface I {
470470
readonly readonlyType: unique symbol;
471471
}
472472
declare const i: I;
473-
declare const constInitToIReadonlyType: symbol;
473+
declare const constInitToIReadonlyType: I["readonlyType"];
474474
declare const constInitToIReadonlyTypeWithTypeQuery: typeof i.readonlyType;
475475
declare const constInitToIReadonlyTypeWithIndexedAccess: I["readonlyType"];
476476
type L = {
@@ -480,8 +480,8 @@ type L = {
480480
};
481481
};
482482
declare const l: L;
483-
declare const constInitToLReadonlyType: symbol;
484-
declare const constInitToLReadonlyNestedType: symbol;
483+
declare const constInitToLReadonlyType: typeof l.readonlyType;
484+
declare const constInitToLReadonlyNestedType: typeof l.nested.readonlyNestedType;
485485
declare const constInitToLReadonlyTypeWithTypeQuery: typeof l.readonlyType;
486486
declare const constInitToLReadonlyNestedTypeWithTypeQuery: typeof l.nested.readonlyNestedType;
487487
declare const constInitToLReadonlyTypeWithIndexedAccess: L["readonlyType"];
@@ -510,15 +510,15 @@ declare const o2: {
510510
method5(p?: symbol): symbol;
511511
};
512512
declare class C0 {
513-
static readonly a: symbol;
514-
static readonly b: symbol;
515-
static readonly c: symbol;
513+
static readonly a: typeof s;
514+
static readonly b: typeof N.s;
515+
static readonly c: typeof N.s;
516516
static d: symbol;
517517
static e: symbol;
518518
static f: symbol;
519-
readonly a: symbol;
520-
readonly b: symbol;
521-
readonly c: symbol;
519+
readonly a: typeof s;
520+
readonly b: typeof N.s;
521+
readonly c: typeof N.s;
522522
d: symbol;
523523
e: symbol;
524524
f: symbol;

‎tsc/testdata/baselines/reference/conformance/uniqueSymbolsDeclarations.types‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const constTypeAndCall: unique symbol = Symbol();
2929

3030
// declaration from initializer
3131
const constInitToConstCall = constCall;
32-
>constInitToConstCall : symbol
32+
>constInitToConstCall : unique symbol
3333
>constCall : unique symbol
3434

3535
const constInitToLetCall = letCall;
@@ -41,7 +41,7 @@ const constInitToVarCall = varCall;
4141
>varCall : symbol
4242

4343
const constInitToConstDeclAmbient = constType;
44-
>constInitToConstDeclAmbient : symbol
44+
>constInitToConstDeclAmbient : unique symbol
4545
>constType : unique symbol
4646

4747
let letInitToConstCall = constCall;
@@ -194,19 +194,19 @@ declare const c: C;
194194
>c : C
195195

196196
const constInitToCReadonlyStaticCall = C.readonlyStaticCall;
197-
>constInitToCReadonlyStaticCall : symbol
197+
>constInitToCReadonlyStaticCall : unique symbol
198198
>C.readonlyStaticCall : unique symbol
199199
>C : typeof C
200200
>readonlyStaticCall : unique symbol
201201

202202
const constInitToCReadonlyStaticType = C.readonlyStaticType;
203-
>constInitToCReadonlyStaticType : symbol
203+
>constInitToCReadonlyStaticType : unique symbol
204204
>C.readonlyStaticType : unique symbol
205205
>C : typeof C
206206
>readonlyStaticType : unique symbol
207207

208208
const constInitToCReadonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall;
209-
>constInitToCReadonlyStaticTypeAndCall : symbol
209+
>constInitToCReadonlyStaticTypeAndCall : unique symbol
210210
>C.readonlyStaticTypeAndCall : unique symbol
211211
>C : typeof C
212212
>readonlyStaticTypeAndCall : unique symbol
@@ -304,7 +304,7 @@ declare const i: I;
304304
>i : I
305305

306306
const constInitToIReadonlyType = i.readonlyType;
307-
>constInitToIReadonlyType : symbol
307+
>constInitToIReadonlyType : unique symbol
308308
>i.readonlyType : unique symbol
309309
>i : I
310310
>readonlyType : unique symbol
@@ -342,13 +342,13 @@ declare const l: L;
342342
>l : L
343343

344344
const constInitToLReadonlyType = l.readonlyType;
345-
>constInitToLReadonlyType : symbol
345+
>constInitToLReadonlyType : unique symbol
346346
>l.readonlyType : unique symbol
347347
>l : L
348348
>readonlyType : unique symbol
349349

350350
const constInitToLReadonlyNestedType = l.nested.readonlyNestedType;
351-
>constInitToLReadonlyNestedType : symbol
351+
>constInitToLReadonlyNestedType : unique symbol
352352
>l.nested.readonlyNestedType : unique symbol
353353
>l.nested : { readonly readonlyNestedType: unique symbol; }
354354
>l : L
@@ -529,17 +529,17 @@ class C0 {
529529
>C0 : C0
530530

531531
static readonly a = s;
532-
>a : symbol
532+
>a : unique symbol
533533
>s : unique symbol
534534

535535
static readonly b = N.s;
536-
>b : symbol
536+
>b : unique symbol
537537
>N.s : unique symbol
538538
>N : typeof N
539539
>s : unique symbol
540540

541541
static readonly c = N["s"];
542-
>c : symbol
542+
>c : unique symbol
543543
>N["s"] : unique symbol
544544
>N : typeof N
545545
>"s" : "s"
@@ -561,17 +561,17 @@ class C0 {
561561
>"s" : "s"
562562

563563
readonly a = s;
564-
>a : symbol
564+
>a : unique symbol
565565
>s : unique symbol
566566

567567
readonly b = N.s;
568-
>b : symbol
568+
>b : unique symbol
569569
>N.s : unique symbol
570570
>N : typeof N
571571
>s : unique symbol
572572

573573
readonly c = N["s"];
574-
>c : symbol
574+
>c : unique symbol
575575
>N["s"] : unique symbol
576576
>N : typeof N
577577
>"s" : "s"

0 commit comments

Comments
 (0)