Fix compiler panic on arrow function visibility diagnostics (Fixes #4629) - #4645
Closed
islamfahmy wants to merge 1 commit into
Closed
Fix compiler panic on arrow function visibility diagnostics (Fixes #4629)#4645islamfahmy wants to merge 1 commit into
islamfahmy wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a compiler crash in declaration emit by preventing arrow-function nodes (and their immediate children) from being routed into symbol-accessibility diagnostic helpers that currently panic on KindArrowFunction, and by making diagnostic formatting more robust when a declaration has no name node.
Changes:
- Added an early guard in
createGetSymbolAccessibilityDiagnosticForNodeto skip arrow functions / arrow-function children for symbol accessibility diagnostics. - Added a fallback in
wrapSimpleDiagnosticSelectorso diagnostics always have a node available for the “declaration name” argument whenast.GetNameOfDeclarationreturnsnil. - Added a new compiler regression test + reference baselines for the reported crash scenario.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| testdata/tests/cases/compiler/arrowFunctionVisibilityPanic.ts | New regression test intended to cover the arrow-function visibility-diagnostic crash scenario. |
| testdata/baselines/reference/compiler/arrowFunctionVisibilityPanic.types | Reference .types baseline for the new test. |
| testdata/baselines/reference/compiler/arrowFunctionVisibilityPanic.symbols | Reference .symbols baseline for the new test. |
| testdata/baselines/reference/compiler/arrowFunctionVisibilityPanic.js | Reference .js (including .d.ts section) baseline for the new test. |
| internal/transformers/declarations/diagnostics.go | Adds arrow-function guard and a GetNameOfDeclaration nil fallback for diagnostic argument construction. |
Comment on lines
+25
to
+28
| typeName := ast.GetNameOfDeclaration(node) | ||
| if typeName == nil { | ||
| typeName = node // Fallback guarantees the regex formatter has enough arguments | ||
| } |
Comment on lines
+6
to
+9
| // 1. Private type | ||
| interface PrivateType { | ||
| secret: string; | ||
| } |
islamfahmy
force-pushed
the
fix/arrow-function-panic
branch
from
July 15, 2026 08:30
38b9ba5 to
824e813
Compare
Author
|
@microsoft-github-policy-service agree |
Member
|
Closing in favor of #4648 - this approach is fundamentally a workaround that layers hackiness up just to cover for a simple missing case, unfortunately. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request: Fix compiler panic on arrow function visibility diagnostics
Description
This PR resolves two compiler panics occurring during the declaration emit phase:
KindArrowFunctionnodes, which leads to an unhandled case panic.export = () => {}),ast.GetNameOfDeclarationreturnsnil. This leaves the diagnostic template with missing arguments, causingdiagnostics.Formatto panic due to index out-of-bounds.Changes
1. Centralized Arrow Function Guard
Added a check in
createGetSymbolAccessibilityDiagnosticForNodeto returnnilearly for arrow functions, matching upstream behavior.2. Anonymous Node Fallback
Updated
wrapSimpleDiagnosticSelectorto fallback to the node itself whenGetNameOfDeclarationreturnsnil. This ensures the diagnostic formatter always receives the required argument count.