Skip to content

feat(compiler): emit missing-extern-declaration diagnostic for orphaned $functions exports#10773

Draft
timotheeguerin wants to merge 3 commits into
microsoft:mainfrom
timotheeguerin:function-require-extern
Draft

feat(compiler): emit missing-extern-declaration diagnostic for orphaned $functions exports#10773
timotheeguerin wants to merge 3 commits into
microsoft:mainfrom
timotheeguerin:function-require-extern

Conversation

@timotheeguerin
Copy link
Copy Markdown
Member

Summary

Fixes #10748

When a JS file exports $functions without a corresponding extern fn declaration in TypeSpec, calling that function silently produces incorrect results (no error, no parameters).

Changes

  • New diagnostic: missing-extern-declaration fires at program check time for ALL orphaned function implementations (regardless of whether the function is called)
  • Checker: Added checkOrphanedFunctionImplementations() in checkProgram() that walks JS source file symbols looking for Function symbols without a matching FunctionDeclarationStatementNode
  • Tests: Refactored functions.test.ts to use per-function JS file testers (avoiding orphan diagnostics in tests)
  • Semantic walker: Updated to use compileAndDiagnose to handle the new diagnostic

Diagnostic message

Function implementation "<name>" is exported in JS via $functions but has no corresponding 'extern fn' declaration in TypeSpec.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the compiler:core Issues for @typespec/compiler label May 22, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 22, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@10773

commit: 87bee3c

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

All changed packages have been documented.

  • @typespec/compiler
Show changes

@typespec/compiler - fix ✏️

Report an error when a function is declared in the $functions map in a JS file but has no corresponding extern fn declaration in TypeSpec. Previously this would silently have no effect.

@azure-sdk-automation
Copy link
Copy Markdown

azure-sdk-automation Bot commented May 22, 2026

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@microsoft-github-policy-service microsoft-github-policy-service Bot added the meta:website TypeSpec.io updates label May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:core Issues for @typespec/compiler meta:website TypeSpec.io updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Defining function in js with $functions without extern fn silently does nothing

1 participant