Skip to content

Warn for string-to-literal narrowing assignments#19603

Open
polatengin wants to merge 3 commits intomainfrom
polatengin/11889-narrowing-assignment-to-union-typed-receiver-should-generate-warning-not-error
Open

Warn for string-to-literal narrowing assignments#19603
polatengin wants to merge 3 commits intomainfrom
polatengin/11889-narrowing-assignment-to-union-typed-receiver-should-generate-warning-not-error

Conversation

@polatengin
Copy link
Copy Markdown
Member

@polatengin polatengin commented May 5, 2026

Description

Allows assignments from plain string values to fixed string-literal receivers, such as 'foo' | 'bar', to compile with a warning when the value may be valid at runtime.

The assignment is treated as narrowed to the receiver’s allowed string literals, matching existing narrowing behavior for bounded values.

Fixes #11889

Example Usage

// mod.bicep
@allowed(['foo', 'bar'])
param foobar string

// main.bicep
param foobar string
module mod './mod.bicep' = {
  name: 'mod'
  params: {
    foobar: foobar
  }
}

This now emits warning-level BCP036 instead of error-level BCP036

Checklist

Microsoft Reviewers: Open in CodeFlow

@polatengin polatengin added this to the v0.41 milestone May 5, 2026
@polatengin polatengin self-assigned this May 5, 2026
@polatengin polatengin added this to Bicep May 5, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Bicep May 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

Test this change out locally with the following install scripts (Action run 25392104965)

VSCode
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-vsix.sh) --run-id 25392104965
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-vsix.ps1) } -RunId 25392104965"
Azure CLI
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-cli.sh) --run-id 25392104965
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-cli.ps1) } -RunId 25392104965"

@stephaniezyen stephaniezyen modified the milestones: v0.41, 0.44 May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Narrowing assignment to union typed receiver should generate warning, not error

2 participants