Azure / Azure/bicep

Nullability warnings are not solved by null checking

Open
#19,641 1 comment 0 reactions 0 assignees View on GitHub
type system type system: control flow
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

**Bicep version**
v0.43.8

**Describe the bug**
When a module accepts a nullable object as a parameter, Bicep still gives a nullability warning when dotting into that object even after checking that it is not null. For example, `vnet.name` and `vnet.resourceGroupName` both give warnings here when they shouldn't:

```bicep
resource vnetResource 'Microsoft.Network/virtualNetworks@2024-01-01' existing = if (vnet != null) {
name: vnet.name // The value of type "null | { name: string, resourceGroupName: string }" may be null at the start of the deployment
scope: resourceGroup(vnet.resourceGroupName) // The value of type "null | { name: string, resourceGroupName: string }" may be null at the start of the deployment
}
```

I'd expect the `if (vnet != null) ` check to make the nullability warnings go away.

**To Reproduce**

```bicep
type Foo = {
bar: string
}

param foo Foo?

resource a 'Microsoft.Network/virtualNetworks@2024-01-01' existing = if (foo != null) {
name: foo.foo // The value of type "null | { name: string, resourceGroupName: string }" may be null at the start of the deployment
}
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the warning with the nullable Foo parameter and the `if (foo != null)` resource condition shown in the issue. Trace the compiler's nullability analysis for property access inside conditional resource bodies. Done means accesses such as `foo.foo`, `vnet.name`, and `vnet.resourceGroupName` no longer warn after the corresponding null check, with regression coverage for the reported examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.