Repository navigation
Commit 3337425
fix(adr-0087): a type literal in an interface or class header leaves its body a type body (#38179)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DDypKu7B9nwbu5WuV7AEio8)_
Fixes #38144
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:用户无感;只影响发版检查工具对「类型收窄」声明的判读,接口或类的声明头里带花括号类型时,成员的类型标注现在能被正确读到。
- 为什么做:属于发版破坏性变更登记检查的收尾工作,替审改动的人堵住一个偏宽的漏判。
- 出错会怎样:最坏情况是检查工具对少数声明误判,表现为某条变更说明被错误拦下或放行;只改检查脚本,可直接撤回。
- 要你做的:无。
## What changes
`scripts/check-adr-0087-registration.mjs`, one file, script only
(publishes nothing, `skip-changeset`).
- **The fix.** `braceOpensTypeBody` read its header back only to the
previous `;`, `{` or `}`. In `export interface
SortableFavoriteRowsProps<T extends { id: string }> {` that stops inside
the constraint's braces, the header reads as `>`, the body is not
classified as a type body, and `sitsInTypePosition` falls back to the
value reading, so an annotated `renderRow: (item: T, drag:
FavoriteRowDragProps) => React.ReactNode;` read as "carries NO return
annotation" (erased; the permissive direction for predicate 4). The
header is now read by a new `braceHeader`, which steps over and blanks a
balanced brace group only when both conditions hold: (1) its opening
brace follows a type-literal position (less-than, comma, open paren,
pipe, ampersand, a lone equals, or the word `extends`); and (2) it sits
inside a less-than, open paren or open bracket that is still open after
it, which `closesAnOpenerBefore` checks by finding the text between the
group and the body brace closing an opener it never opened. Every type
literal a declaration header carries meets (2): constraints and defaults
(`<T extends { id: string }>`, `<T = {}>`), heritage type arguments
(`Base<{ a: 1 }>`), mixin calls. A brace that closes a statement never
does, so a type alias closed by a bare brace with no semicolon (the
ThemeProvider shape) stays a statement boundary, and so does a prior
`class A {}`. Blanking keeps a keyword inside a stepped-over group (`{
class: 1 }`) out of the header.
- **Review fix (S1, round 1).** Condition (2) above is new on this head.
At af759f4 the equals arm stepped across a statement boundary with no
semicolon: in `ui/packages/app-shell/src/chrome/ThemeProvider.tsx` lines
13-21, `type ThemeProviderState = { ... }` is closed by a bare brace and
followed by `const initialState: ThemeProviderState = {`, so that value
literal got the alias's `type ... =` header and `setTheme: () => null`
read as a function type returning `null`. The same step also attached
the alias to the import before it, so the alias's own `setTheme: (theme:
Theme) => void` read as unannotated. Conditional-type (`extends`) and
union (`|`) aliases with no semicolon had the same leak.
- **N1.** `containerBodiesFor`'s docstring names all four kinds (object
literal, class, interface, type-literal alias) and the companion-object
case.
- **N2.** Predicate 4's HEAD-side refusal prose is reflowed: "is
REPORTED rather than guessed at" no longer breaks early.
- **N3.** The companion object (`interface X` plus an object literal `X
= {`) is pinned as AMBIGUOUS (TSO-I17).
**The real instance**, through the shipping reader
(`readTypeSurfaceRef`) on
`ui/packages/app-shell/src/layout/SortableFavoriteRows.tsx`, at
`origin/main` 9dca109 vs this branch:
```text
before SortableFavoriteRowsProps.renderRow {"shape":"`SortableFavoriteRowsProps.renderRow`, which carries NO return annotation","type":null,"erased":true}
after SortableFavoriteRowsProps.renderRow {"shape":"the return annotation of `SortableFavoriteRowsProps.renderRow`","type":"React.ReactNode","erased":false}
before SortableFavoriteRowsProps.onReorder {... "type":null,"erased":true}
after SortableFavoriteRowsProps.onReorder {... "type":"void","erased":false}
```
**Both review instances**, before (af759f4) and after (this head),
compared with origin/main 9dca109:
```text
main 9dca109 af759f4 this head
ThemeProvider.tsx bare setTheme (alias, line 15) void erased (NO) void
ThemeProvider.tsx lines 13-21, value setTheme null (value) "null" (type) null (value)
app-generator.ts emitted theme-provider text, alias void null void
app-generator.ts emitted theme-provider text, value null (value) null null (value)
app-generator.ts itself, bare setTheme not found not found not found
```
In `app-generator.ts` itself the shape is inside a template literal,
which the reader masks, so the file has no `setTheme` definition. The
rows above read the emitted text, which is what the reviewer's lifted
functions saw.
## Tests
New pins in the gate's own `--self-test`:
- TSO-U38: interface whose type-parameter constraint is a type literal
(the real instance's shape).
- TSO-U39: a type literal in a type-parameter default and in interface
heritage type arguments.
- TSO-U40: a class whose constraint, `extends` and `implements` clauses
all carry type literals.
- TSO-U41, TSO-U42 (lit controls): a class body before an object literal
still ends that literal's header; a stepped-over `{ class: 1 }` is
blanked; an object literal whose own header carries a type argument
stays a value. Green with and without the fix.
- TSO-U43 (lit control, the ThemeProvider shape): an alias with no
semicolon, then a typed `const` literal, read both as lines 13-21 alone
and under the file's head. The literal's arrow stays a VALUE.
- TSO-U44: in the same file, the alias member reads `void`.
- TSO-U45: the same statement boundary behind a conditional type
(`extends`) and a union (`|`) with no semicolon.
- TSO-I17 (N3): the companion object is AMBIGUOUS, "opens 2 object
literals and interface bodies".
- TSO-I18: the dotted spelling `SortableRowsProps.renderRow` behind a
header type literal resolves to `React.ReactNode`.
- TSO-I19 / TSO-I20: end to end through `scan()`: a concrete base behind
the header is refused by predicate 4 (narrowed-from-erased is FALSE); a
truly erased base (`=> any`) is admitted.
Battery floors raised to the measured counts: `TSO-U` 37 to 45, `TSO-I`
20 to 25. The #38093/#38137 pins (R8, R9, G2, TSO-R8, TSO-R9, TSO-G2,
TSO-U31 to U37, the TSO-I battery) stay green.
<details><summary>Self-test, final head 9e13d6d</summary>
```text
node scripts/check-adr-0087-registration.mjs --self-test EXIT=0
✓ check-adr-0087-registration --self-test: 867 assertions over real temp git repos (real scan()/assertInputs() path)
```
(854 assertions at origin/main 9dca109.)
</details>
<details><summary>Ablation (fix reverted on disk, braceHeader returning
the old back-to-previous-brace header)</summary>
```text
✗ check-adr-0087-registration --self-test -- 6 failure(s)
• TSO-U38 • TSO-U39 • TSO-U40 • TSO-I18
• TSO-I19 (message must match "predicate 4: narrowed-from-erased] is FALSE"; actual: "still UNANNOTATED")
• TSO-I20 (expected GREEN; got "still UNANNOTATED" at HEAD)
```
TSO-U41, TSO-U42 (lit controls) and TSO-I17 stay green under the
ablation, as designed. Restored with `git checkout HEAD --
scripts/check-adr-0087-registration.mjs`, `git status --porcelain`
empty.
</details>
<details><summary>Ablation 2 (round 1): the closesAnOpenerBefore guard
commented out at 9e13d6d</summary>
```text
✗ check-adr-0087-registration --self-test -- 3 failure(s)
• TSO-U43 (the ThemeProvider lit control) • TSO-U44 • TSO-U45
```
U38 to U42 and I17 to I20 stay green under this ablation, because the
guard does not affect them. Restored with `git checkout HEAD --
scripts/check-adr-0087-registration.mjs`, `git status --porcelain`
empty.
</details>
## Acceptance notes
- The end-to-end red under the ablation is the strict direction ("still
UNANNOTATED at HEAD"), because both revs share the header. The
permissive direction the card names (a concrete base read as erased
while HEAD reads annotated) is what TSO-U38 to U40 and TSO-I18 pin at
the reader.
- Header positions not stepped over: a type literal after a colon at
header depth 0 does not arise in an interface or class header; an
object-literal argument in a class `extends` expression (`extends
mixin({ ... })`) sits behind an open paren and is stepped over.
## Verification
Read first: `braceHeader` and `closesAnOpenerBefore` (the risk hunk is
the pair of conditions that decide whether a closing brace ends the
header), then TSO-U41 to U45.
Two-minute check: `node scripts/check-adr-0087-registration.mjs
--self-test` prints `867 assertions`.
<details><summary>Local gate subset at 9e13d6d (dispatch-gates
--commands, 34 families; --ran: 34 derived, 34 run, 0 NOT-MEASURED, a
derived zero)</summary>
All 34 commands, including `pnpm check:pm-dispatch-gates`, ran one after
another, each exit code captured before any pipe, and every one exited
0. Highlights: `check-adr-0087-registration --base origin/main` exit 0;
`--self-test` exit 0, 867 assertions; `check:nul-bytes` exit 0;
`check:entry-guard` exit 0; `check:scripts-symbol-anchors` exit 0.
`overlap-check` VERDICT clean: merges cleanly into origin/main
4f7aa88. Every other family CI runs is read from this PR's
check-runs, not re-run locally.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4cxRDKprCtjpEdtiPFW)_
<!-- signed: repo:objectstack#1 · os-elon-musk ·
session_016WV4cxRDKprCtjpEdtiPFW -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 65ad1b4 commit 3337425
1 file changed
Lines changed: 172 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
492 | 492 | | |
493 | 493 | | |
494 | 494 | | |
495 | | - | |
| 495 | + | |
496 | 496 | | |
497 | 497 | | |
498 | | - | |
| 498 | + | |
499 | 499 | | |
500 | 500 | | |
501 | 501 | | |
| |||
3686 | 3686 | | |
3687 | 3687 | | |
3688 | 3688 | | |
3689 | | - | |
3690 | | - | |
| 3689 | + | |
| 3690 | + | |
| 3691 | + | |
3691 | 3692 | | |
3692 | 3693 | | |
3693 | | - | |
3694 | | - | |
3695 | | - | |
| 3694 | + | |
3696 | 3695 | | |
3697 | 3696 | | |
3698 | 3697 | | |
3699 | 3698 | | |
3700 | 3699 | | |
3701 | 3700 | | |
3702 | 3701 | | |
| 3702 | + | |
| 3703 | + | |
| 3704 | + | |
| 3705 | + | |
| 3706 | + | |
| 3707 | + | |
| 3708 | + | |
| 3709 | + | |
| 3710 | + | |
| 3711 | + | |
| 3712 | + | |
| 3713 | + | |
| 3714 | + | |
| 3715 | + | |
| 3716 | + | |
| 3717 | + | |
| 3718 | + | |
| 3719 | + | |
| 3720 | + | |
| 3721 | + | |
| 3722 | + | |
| 3723 | + | |
| 3724 | + | |
| 3725 | + | |
| 3726 | + | |
| 3727 | + | |
| 3728 | + | |
| 3729 | + | |
| 3730 | + | |
| 3731 | + | |
| 3732 | + | |
| 3733 | + | |
| 3734 | + | |
| 3735 | + | |
| 3736 | + | |
| 3737 | + | |
| 3738 | + | |
| 3739 | + | |
| 3740 | + | |
| 3741 | + | |
| 3742 | + | |
| 3743 | + | |
| 3744 | + | |
| 3745 | + | |
| 3746 | + | |
| 3747 | + | |
| 3748 | + | |
| 3749 | + | |
| 3750 | + | |
| 3751 | + | |
| 3752 | + | |
| 3753 | + | |
| 3754 | + | |
| 3755 | + | |
| 3756 | + | |
| 3757 | + | |
| 3758 | + | |
| 3759 | + | |
| 3760 | + | |
| 3761 | + | |
| 3762 | + | |
| 3763 | + | |
| 3764 | + | |
| 3765 | + | |
| 3766 | + | |
| 3767 | + | |
| 3768 | + | |
| 3769 | + | |
| 3770 | + | |
| 3771 | + | |
| 3772 | + | |
| 3773 | + | |
| 3774 | + | |
3703 | 3775 | | |
3704 | 3776 | | |
3705 | 3777 | | |
| |||
3809 | 3881 | | |
3810 | 3882 | | |
3811 | 3883 | | |
3812 | | - | |
3813 | | - | |
3814 | | - | |
3815 | | - | |
3816 | | - | |
3817 | | - | |
| 3884 | + | |
| 3885 | + | |
| 3886 | + | |
| 3887 | + | |
| 3888 | + | |
| 3889 | + | |
| 3890 | + | |
| 3891 | + | |
3818 | 3892 | | |
3819 | 3893 | | |
3820 | 3894 | | |
| |||
4583 | 4657 | | |
4584 | 4658 | | |
4585 | 4659 | | |
4586 | | - | |
4587 | | - | |
4588 | | - | |
| 4660 | + | |
| 4661 | + | |
| 4662 | + | |
4589 | 4663 | | |
4590 | 4664 | | |
4591 | 4665 | | |
| |||
7931 | 8005 | | |
7932 | 8006 | | |
7933 | 8007 | | |
| 8008 | + | |
| 8009 | + | |
| 8010 | + | |
| 8011 | + | |
| 8012 | + | |
| 8013 | + | |
| 8014 | + | |
| 8015 | + | |
| 8016 | + | |
| 8017 | + | |
| 8018 | + | |
| 8019 | + | |
| 8020 | + | |
| 8021 | + | |
| 8022 | + | |
| 8023 | + | |
| 8024 | + | |
| 8025 | + | |
| 8026 | + | |
| 8027 | + | |
| 8028 | + | |
| 8029 | + | |
| 8030 | + | |
| 8031 | + | |
| 8032 | + | |
| 8033 | + | |
| 8034 | + | |
| 8035 | + | |
| 8036 | + | |
| 8037 | + | |
| 8038 | + | |
| 8039 | + | |
| 8040 | + | |
| 8041 | + | |
| 8042 | + | |
| 8043 | + | |
| 8044 | + | |
| 8045 | + | |
7934 | 8046 | | |
7935 | 8047 | | |
7936 | 8048 | | |
| |||
8521 | 8633 | | |
8522 | 8634 | | |
8523 | 8635 | | |
| 8636 | + | |
| 8637 | + | |
| 8638 | + | |
| 8639 | + | |
| 8640 | + | |
| 8641 | + | |
| 8642 | + | |
| 8643 | + | |
| 8644 | + | |
| 8645 | + | |
| 8646 | + | |
| 8647 | + | |
| 8648 | + | |
| 8649 | + | |
| 8650 | + | |
| 8651 | + | |
| 8652 | + | |
| 8653 | + | |
| 8654 | + | |
| 8655 | + | |
| 8656 | + | |
| 8657 | + | |
| 8658 | + | |
| 8659 | + | |
| 8660 | + | |
| 8661 | + | |
| 8662 | + | |
| 8663 | + | |
| 8664 | + | |
| 8665 | + | |
| 8666 | + | |
| 8667 | + | |
| 8668 | + | |
| 8669 | + | |
| 8670 | + | |
| 8671 | + | |
| 8672 | + | |
| 8673 | + | |
| 8674 | + | |
| 8675 | + | |
| 8676 | + | |
| 8677 | + | |
| 8678 | + | |
| 8679 | + | |
8524 | 8680 | | |
8525 | 8681 | | |
8526 | 8682 | | |
| |||
0 commit comments