Skip to content

Fix compiler crash when decorator fn argument contains invalid reference#10858

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-compiler-crash-decorator
Draft

Fix compiler crash when decorator fn argument contains invalid reference#10858
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-compiler-crash-decorator

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 2, 2026

When an extern fn used as a decorator argument receives an invalid reference (e.g., a typo), the compiler was passing the function's declared return type constraint to the decorator implementation instead of skipping the decorator call. This caused internal crashes in decorator implementations that access properties on the argument.

extern fn myFn(target: Reflection.Operation): Reflection.Operation;
extern dec myDec(target: Reflection.Operation, override: Reflection.Operation);

op test(): void;
@@myDec(test, myFn(invalidref));  // crash: $myDec receives Model "Operation" instead of skipping

Changes

  • checkFunctionCall: Return errorType when arguments are unsatisfied outside template declarations, instead of returning the constraint type which passes downstream assignability checks
  • checkFunctionCallArguments: Skip assignability check when resolved argument is errorType, preventing spurious secondary diagnostics (only the primary invalid-ref error is reported)
  • Test: Added regression test for augment decorator with invalid fn argument reference
  • Test updates: Two existing tests updated to expect errorType instead of the constraint type when function calls fail due to argument errors

…ference

When an extern fn is called with an invalid reference as an argument,
return errorType instead of the declared return type constraint. This
prevents the decorator from being called with an incorrect type and
avoids internal compiler crashes.

Also skip assignability checks in checkFunctionCallArguments when the
resolved argument is errorType to avoid spurious secondary diagnostics.

Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the compiler:core Issues for @typespec/compiler label Jun 2, 2026
Copilot AI changed the title [WIP] Fix compiler crash for decorator with invalid extern fn reference Fix compiler crash when decorator fn argument contains invalid reference Jun 2, 2026
Copilot AI requested a review from markcowl June 2, 2026 02:30
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler crash: decorator called with return type Model when extern fn argument is an invalid reference

2 participants