Skip to content

Fix compiler panic on arrow function visibility diagnostics (Fixes #4629) - #4645

Closed
islamfahmy wants to merge 1 commit into
microsoft:mainfrom
islamfahmy:fix/arrow-function-panic
Closed

Fix compiler panic on arrow function visibility diagnostics (Fixes #4629)#4645
islamfahmy wants to merge 1 commit into
microsoft:mainfrom
islamfahmy:fix/arrow-function-panic

Conversation

@islamfahmy

Copy link
Copy Markdown

Pull Request: Fix compiler panic on arrow function visibility diagnostics

Description

This PR resolves two compiler panics occurring during the declaration emit phase:

  1. Arrow Function Panic: The compiler attempts to generate visibility diagnostics for parameters/return types of KindArrowFunction nodes, which leads to an unhandled case panic.
  2. Formatting Panic: For anonymous exports (e.g., export = () => {}), ast.GetNameOfDeclaration returns nil. This leaves the diagnostic template with missing arguments, causing diagnostics.Format to panic due to index out-of-bounds.

Changes

1. Centralized Arrow Function Guard

Added a check in createGetSymbolAccessibilityDiagnosticForNode to return nil early for arrow functions, matching upstream behavior.

2. Anonymous Node Fallback

Updated wrapSimpleDiagnosticSelector to fallback to the node itself when GetNameOfDeclaration returns nil. This ensures the diagnostic formatter always receives the required argument count.

Copilot AI review requested due to automatic review settings July 15, 2026 02:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 createGetSymbolAccessibilityDiagnosticForNode to skip arrow functions / arrow-function children for symbol accessibility diagnostics.
  • Added a fallback in wrapSimpleDiagnosticSelector so diagnostics always have a node available for the “declaration name” argument when ast.GetNameOfDeclaration returns nil.
  • 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
islamfahmy force-pushed the fix/arrow-function-panic branch from 38b9ba5 to 824e813 Compare July 15, 2026 08:30
@islamfahmy

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@weswigham

Copy link
Copy Markdown
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.

@weswigham weswigham closed this Jul 15, 2026
@islamfahmy
islamfahmy deleted the fix/arrow-function-panic branch July 18, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants