…defaults
Operations resolved template parameter defaults before entering the
template declaration scope, unlike models and interfaces. A decorated
template used as an operation parameter default (e.g. the ARM
`Properties = TagsUpdateModel<Resource>` pattern) therefore ran its
decorators with the still-unresolved template parameter, storing
unresolved `{name}` friendly names that leaked into emitted file names.
Move the InTemplateDeclaration flag before checkTemplateDeclaration in
checkOperation, matching checkModelStatement.
Fixes microsoft#11454
Fixes #11454
Problem
checkOperationresolves template parameter defaults (viacheckTemplateDeclaration) before entering theInTemplateDeclarationscope — unlikecheckModelStatementand interface/union checks, which set the flag first.As a result, when a decorated template is used as an operation template parameter default (the ARM tags-update pattern, e.g.
op foo<Resource, Properties extends {} = TagsUpdateModel<Resource>>(...)), the default is instantiated withResourcestill an unresolvedTemplateParameter, andskipDecoratorsisfalse. The decorators on the default type (@friendlyName,@doc, …) therefore run with an unresolved template parameter argument and store unresolved{name}strings. In@typespec/http-server-csharpthis surfaced as a model file named{name}TagsUpdate.csinstead ofFooResourceTagsUpdate.cs.A decorator should never run with a
TemplateParameterargument — the real bug is the ordering, not the emitter.Fix
In
checkOperation, setCheckFlags.InTemplateDeclarationbefore callingcheckTemplateDeclaration, mirroringcheckModelStatement. Operations now enter the template declaration scope before resolving parameter defaults, so decorators on those defaults are no longer executed with the still-unresolved template parameter.Tests
@trackdecorator that records the kind of its argument. It asserts@tracknever runs with aTemplateParameter(only the concreteModel). Verified: fails before the fix, passes after.{/}placeholder.Background
This supersedes and replaces #11459, which had diverged from its original purpose and accumulated several earlier band-aid attempts. This PR contains only the root-cause compiler fix plus tests.