Skip to content

Add diagnostic for valueof used in scalar initializer parameters#10878

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-bad-diagnostics-mixed-constraints
Draft

Add diagnostic for valueof used in scalar initializer parameters#10878
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-bad-diagnostics-mixed-constraints

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 3, 2026

Using valueof in a scalar initializer parameter constraint produced no diagnostic at the definition site. The error only surfaced at the call site as an unhelpful "unassignable to ErrorType" message, because ValueOfExpression fell through to errorType in checkNode.

Scalar initializer parameters implicitly accept values, so valueof is redundant and invalid. This adds an explicit diagnostic at the definition site.

Changes

  • New diagnostic scalar-init-valueof in messages.ts — clear error telling the user to remove valueof
  • Validation in checkScalarConstructor — detects ValueOfExpression nodes on parameter types before processing them
  • Test in scalar.test.ts verifying the diagnostic fires

Example

scalar S {
  init i(s: valueof string);  // ← now emits: "Scalar initializer parameters implicitly accept values. Remove 'valueof' from the parameter type."
}

…izer parameters

Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bad diagnostics for mixed constraints on scalar initializers Add diagnostic for valueof used in scalar initializer parameters Jun 3, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the compiler:core Issues for @typespec/compiler label Jun 3, 2026
Copilot AI requested a review from markcowl June 3, 2026 19:01
@markcowl
Copy link
Copy Markdown
Contributor

markcowl commented Jun 3, 2026

/azp run typespec - PR Tools

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 3, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@10878

commit: 38966a6

@azure-sdk-automation
Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

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] Bad diagnostics when scalar initializer constraint is mixed

2 participants