Repository navigation
fix(compiler): preserve templated scalar initializer types - #12510
Sylvester Kaczmarek (sylvesterkaczmarek) wants to merge 3 commits into
Conversation
|
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. |
|
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 |
Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
|
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. |
There was a problem hiding this comment.
🟡 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
Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
|
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. |

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
pnpm test --maxWorkers=4: 10,670 passed, 25 skipped across 500 passing files and one skipped file.pnpm build: 48 tasks successful, including engineering type checks and compiler external-signature generation.Test<string>.from(123)through a scalar alias with the expectedinvalid-argumentdiagnostic.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.