fix(compiler): error when $functions implementation has no corresponding extern fn declaration#10765
Draft
Copilot wants to merge 4 commits into
Draft
fix(compiler): error when $functions implementation has no corresponding extern fn declaration#10765Copilot wants to merge 4 commits into
extern fn declaration#10765Copilot wants to merge 4 commits into
Conversation
…declaration Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/ee46de1b-9e2a-4264-8477-662cf80b09ae Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
… tester pollution Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/ee46de1b-9e2a-4264-8477-662cf80b09ae Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add error handling for undefined function implementation
fix(compiler): error when $functions implementation has no corresponding May 21, 2026
extern fn declaration
| default: "Extern declaration must have an implementation in JS file.", | ||
| }, | ||
| }, | ||
| "implementation-without-extern": { |
Member
There was a problem hiding this comment.
@copilot lets add a documentation url and a markdown document for it like for triple-quote error
| expectDiagnosticEmpty(diagnostics.filter((d) => d.code !== "experimental-feature")); | ||
| expectDiagnosticEmpty( | ||
| diagnostics.filter( | ||
| (d) => d.code !== "experimental-feature" && d.code !== "implementation-without-extern", |
Member
There was a problem hiding this comment.
@copilot why do we need to filter this, shouldn't the test not testing for this error hjave an extern dec?
commit: |
…thout-extern, remove filter from helpers, fix tests to use per-function testers Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/e622bfe1-d9ab-4d99-b9a7-aaa7bb298665 Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
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.
Defining a function in
$functionswithout a matchingextern fndeclaration in TypeSpec silently had no effect — the implementation was simply ignored, leading to confusing behavior where calling the function would use a default no-op implementation.Changes
New diagnostic
implementation-without-extern: Reported duringcheckProgram()for any function in a JS$functionsmap that has no correspondingextern fndeclaration in TypeSpec.Documentation: Added
urlanddescriptionfields to the diagnostic and created a dedicated markdown documentation page atwebsite/src/content/docs/docs/standard-library/diags/implementation-without-extern.md(following the same pattern as other diagnostics liketriple-quote).Checker: Added
checkJsImplementations()(called fromcheckProgram()) that walks all JS source file symbol tables and checks eachFunction | Implementationsymbol for a pairedFunctionDeclarationStatementin the merged symbol's declarations.Test helpers:
expectFunctionDiagnosticsEmpty/expectFunctionDiagnosticsonly filter the existingexperimental-featurewarning. Tests are now correctly structured so that every$functionsentry has a correspondingextern fndeclaration, eliminating the need to suppressimplementation-without-externin test helpers.Test fixes: Corrected
semantic-walker.test.ts(removed shared$functionsfixture, scoped it to the one test that needs it) andfunctions.test.ts(replaced shared multi-function testers with per-function testers so each test only registers the exact implementations it declares withextern fn).4 new tests covering the error for both root-namespace and namespaced
$functionsentries, with and without a matchingextern fn.Example
// lib.tsp — no `namespace TestFn { extern fn testFn(...); }` → now emits errorThe fix surfaces
implementation-without-externpointing at the JS source file, making namespace mismatches and missing declarations immediately diagnosable.