From d204ef71d627632c31fc73c195e2679466d31eda Mon Sep 17 00:00:00 2001 From: Malte Ubl Date: Mon, 19 Oct 2026 13:56:00 -0700 Subject: [PATCH] Keep the private-brand diagnostics on shapes that still refuse Function-local classes whose private names are used only on `this` now compile, so the two diagnostics fixtures test a brand check on another object instead. Co-Authored-By: Claude Opus 5.5 --- tests/diagnostics/local-class-boundaries.ts | 2 +- tests/diagnostics/local-class-type-query-brand.ts | 6 +++++- tests/harness/__snapshots__/local-class-boundaries.ts.txt | 6 +++--- .../__snapshots__/local-class-type-query-brand.ts.txt | 8 ++++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/diagnostics/local-class-boundaries.ts b/tests/diagnostics/local-class-boundaries.ts index a82dfb869..2c43e9900 100644 --- a/tests/diagnostics/local-class-boundaries.ts +++ b/tests/diagnostics/local-class-boundaries.ts @@ -1,4 +1,4 @@ -function privateBrand() { return class { #value = 1; read(): number { return this.#value; } }; } +function privateBrand() { return class { #value = 1; has(other: object): boolean { return #value in other; } }; } function selfName() { return class Local { copy() { return new Local(); } }; } class Base {} function derived() { return class extends Base {}; } diff --git a/tests/diagnostics/local-class-type-query-brand.ts b/tests/diagnostics/local-class-type-query-brand.ts index 566304627..aeb905cad 100644 --- a/tests/diagnostics/local-class-type-query-brand.ts +++ b/tests/diagnostics/local-class-type-query-brand.ts @@ -1,11 +1,15 @@ // The same speculative element-type query, reaching a function-local class -// with a private brand through the function's returned array. +// with a private brand through the function's returned array. The brand is +// tested on another object, so the evaluations' private names must differ. function make() { class Box { #v = 1; read(): number { return this.#v; } + same(other: object): boolean { + return #v in other; + } } return [new Box()]; } diff --git a/tests/harness/__snapshots__/local-class-boundaries.ts.txt b/tests/harness/__snapshots__/local-class-boundaries.ts.txt index 04dbc336c..6706a1278 100644 --- a/tests/harness/__snapshots__/local-class-boundaries.ts.txt +++ b/tests/harness/__snapshots__/local-class-boundaries.ts.txt @@ -1,12 +1,12 @@ local-class-boundaries.ts:1:34 - error SC1090: function-local classes with private brands are not supported yet - 1 | function privateBrand() { return class { #value = 1; read(): number { return this.#value; } }; } - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 1 | function privateBrand() { return class { #value = 1; has(other: object): boolean { return #value in other; } }; } + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2 | function selfName() { return class Local { copy() { return new Local(); } }; } local-class-boundaries.ts:2:64 - error SC1090: named self references inside function-local classes are not supported yet - 1 | function privateBrand() { return class { #value = 1; read(): number { return this.#value; } }; } + 1 | function privateBrand() { return class { #value = 1; has(other: object): boolean { return #value in other; } }; } 2 | function selfName() { return class Local { copy() { return new Local(); } }; } | ^~~~~ 3 | class Base {} diff --git a/tests/harness/__snapshots__/local-class-type-query-brand.ts.txt b/tests/harness/__snapshots__/local-class-type-query-brand.ts.txt index 6db3418a8..ea877dec3 100644 --- a/tests/harness/__snapshots__/local-class-type-query-brand.ts.txt +++ b/tests/harness/__snapshots__/local-class-type-query-brand.ts.txt @@ -1,6 +1,6 @@ -local-class-type-query-brand.ts:4:3 - error SC1090: function-local classes with private brands are not supported yet +local-class-type-query-brand.ts:5:3 - error SC1090: function-local classes with private brands are not supported yet - 3 | function make() { - 4 | class Box { + 4 | function make() { + 5 | class Box { | ^~~~~~~~~~~ - 5 | #v = 1; \ No newline at end of file + 6 | #v = 1; \ No newline at end of file