Skip to content

fix(compiler): preserve templated scalar initializer types - #12510

Open
Sylvester Kaczmarek (sylvesterkaczmarek) wants to merge 3 commits into
microsoft:mainfrom
sylvesterkaczmarek:fix/12506-templated-scalar-initializers
Open

Sylvester Kaczmarek (sylvesterkaczmarek) wants to merge 3 commits into
microsoft:mainfrom
sylvesterkaczmarek:fix/12506-templated-scalar-initializers

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor

Summary

Fixes #12506.

Keep scalar initializer lookup bound to the instantiated scalar, including aliases and inherited constructors. Resolve initializer parameters with the active template mapper instead of reusing an unresolved declaration-level parameter. Existing assignability rules are unchanged.

Add regressions for the reported assignment, exact scalar identity, multiple instantiations in either order, default arguments, scalar/constructor aliases, inherited initializers, and invalid argument types. Include a compiler changelog entry. No dependency or lockfile changes.

Validation

  • Full workspace pnpm test --maxWorkers=4: 10,670 passed, 25 skipped across 500 passing files and one skipped file.
  • Compiler end-to-end suite: 45 passed.
  • Full pnpm build: 48 tasks successful, including engineering type checks and compiler external-signature generation.
  • Full formatter and type-aware lint passed, with zero lint warnings or errors.
  • Before the fix, the focused three-file run had 14 failed and 33 passed; the same run passes all 47 tests with the fix. Expanded related coverage passed 772 tests.
  • Independent pre-submission review found no actionable defects; its 888 focused repository tests and 30 additional probes passed.
  • The built CLI accepts the exact issue reproduction and still rejects Test<string>.from(123) through a scalar alias with the expected invalid-argument diagnostic.

Validated on macOS arm64 with the repository-pinned Node 26.5.1 and pnpm 11.10.0. Full validation ran in an identical-source isolated checkout to avoid unrelated home-directory module resolution. Source hashes match the submitted files. Hosted CI and maintainer review remain pending.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the compiler:core Issues for @typespec/compiler label Nov 6, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the stale Mark a PR that hasn't been recently updated and will be closed. label Nov 20, 2026
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

Hi @Sylvester Kaczmarek (@sylvesterkaczmarek). Your PR has had no update for 14 days and it is marked as a stale PR. If it is not updated within 14 additional days, the PR will automatically be closed. The stale label is removed automatically when you update or comment on your PR, or when a maintainer reviews it. You can also remove the label manually.

Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor Author

Updated this PR onto current TypeSpec main (911b52d) in signed-off merge commit 21ae810. The change remains limited to the original three files: scalar initializer resolution, focused regressions and changelog. On the updated branch, I built the tmlanguage dependency and compiler, then ran the complete compiler suite locally with pinned Node 26/pnpm 11: 4,791 passed, 6 skipped, zero failures (167 test files). The specific templated-scalar tests passed 16/16. No root-wide workspace re-run or hosted CI result is claimed for this merge. I've marked the PR ready for maintainer review; any compatibility issues from upstream CI can be addressed on this branch.

Copilot AI balanced review requested due to automatic review settings November 20, 2026 19:27
@microsoft-github-policy-service microsoft-github-policy-service Bot removed the stale Mark a PR that hasn't been recently updated and will be closed. label Nov 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Calls to deprecated initializers through templated scalar aliases bypass the deprecation check, suppressing warnings and requiring a fix with regression coverage.

1 open issue
What changed in this PR

Fixes #12506 by keeping scalar initializer lookup tied to the instantiated scalar and resolving parameter types with the active template mapper.

Changes:

  • Late-binds scalar constructors to preserve instantiated type identity.
  • Adds regressions for aliases, inheritance, default arguments, instantiation order, and invalid arguments.
  • Adds a compiler fix changelog entry.
File Description
packages/​compiler/​test/​checker/​values/​templated-scalar-values.test.ts Adds templated scalar initializer regression coverage.
packages/​compiler/​src/​core/​checker.ts Preserves scalar instantiation bindings and resolves mapped parameter types.
.chronus/​changes/​fix-templated-scalar-initializers.md Documents the compiler fix.

Review effort: Balanced

Comment thread packages/compiler/src/core/checker.ts Resolved
Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 21:19
@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor Author

Thanks for catching this. The late-bound scalar-constructor path now reaches the existing deprecation diagnostic checks without changing the return path for other late-bound types. Added a regression for a deprecated initializer called through Test alias. Signed commit c1b12d7 is pushed; the compiler build, 184 focused/deprecation tests and full compiler suite (4,792 passed, 6 skipped) passed locally. Hosted CI and maintainer review remain pending.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the templated scalar initializer fix.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
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.

Templated scalar value assignment issue

2 participants