Sitelet https://github.com/microsoft/TypeScript/pull/63989
Skip to content

Fix panic in declaration emit for export default arrow/function expression with unnameable inferred return type - #63989

Draft
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 3 commits into
mainfrom
copilot/issue-4629-fix-diag-emission
Draft

Fix panic in declaration emit for export default arrow/function expression with unnameable inferred return type#63989
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 3 commits into
mainfrom
copilot/issue-4629-fix-diag-emission

Conversation

Copilot AI commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

export default () => makeFoo() (or a function expression) whose inferred return type contains a symbol that cannot be named from the exporting module crashed the compiler with panic("Diagnostic emitted without context") instead of emitting TS4082, as TS 6.x did.

Root cause

  • transformExportAssignment's ast.IsFunctionLike(unwrapped) branch promotes arrow/function-expression default exports to a function declaration via transformFunctionLikeToDeclarationensureTypeserializeReturnTypeForSignature.
  • Unlike the sibling non-function fallback branch a few lines below, this branch never installed a getSymbolAccessibilityDiagnostic context or pushed an error fallback node before serializing.
  • When the checker reports a CannotBeNamed accessibility result during return-type serialization, it fell through to the file-level default handler, which is just panic(...).

Fix

  • Install the same Default_export_of_the_module_has_or_is_using_private_name_0 diagnostic context and PushErrorFallbackNode(assignment)/PopErrorFallbackNode() pair around the function-like promotion, matching the parity already present in the fallback branch below it.

Tests

  • Added declarationEmitDefaultExportArrowFunctionPrivateName.ts and declarationEmitDefaultExportFunctionExpressionPrivateName.ts, covering both export default () => ... and export default (function () {...}) forms with a cross-module unique-symbol-keyed member causing an unnameable inferred return type. Both now emit TS4082 instead of crashing.

…ssion

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix panic during declaration emit for export default arrow functions Fix panic in declaration emit for export default arrow/function expression with unnameable inferred return type Aug 24, 2026

@weswigham Wesley Wigham (weswigham) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copilot rather than duplicating the exact same logic in basically every branch of transforming the export, why not just move the existing getSymbolAccessibilityDiagnostic (and fallback node push) assignment below up to before unwrapped := so it covers the case in question?

…ssignment

Co-authored-by: weswigham <2932786+weswigham@users.noreply.github.com>

Copilot AI commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Copilot rather than duplicating the exact same logic in basically every branch of transforming the export, why not just move the existing getSymbolAccessibilityDiagnostic (and fallback node push) a...

Good call, done in 7c40297 - moved the diagnostic context assignment and PushErrorFallbackNode above unwrapped := so it's set once and shared across all branches, with a matching PopErrorFallbackNode() added before each return.

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.

Panic "Diagnostic emitted without context" ts-go in declaration emit for export default arrow/function expression with non-portable inferred return type

3 participants