dotnet / dotnet/runtime

ILC emits false-positive trim/AOT warnings when `[FeatureSwitchDefinition]` property is combined with `||`

Open
#129,296 5 comments 0 reactions 1 assignee Claimed by @sbomer View on GitHub
area-Tools-ILLink needs-author-action
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

### Description

When a `[FeatureSwitchDefinition]` property is the left operand of `||`, ILC emits IL2026/IL3050 for the else branch even though it's correctly trimmed at publish time.

```csharp
// No warnings
if (FeatureSwitch) { Safe(); } else { Unsafe(); }

// False-positive IL2026/IL3050 on Unsafe()
if (FeatureSwitch || RuntimeCheck()) { Safe(); } else { Unsafe(); }
```

### Reproduction Steps

https://github.com/Nigusu-Allehu/TestFeatureSwitch

### Expected behavior

I would expect constant folding in the if condition as the value of the runtime check does not matter if the feature switch is `true`.

### Actual behavior

IL2026 and IL3050 warnings from the code path that should have been trimmed out

### Regression?

IDK

### Known Workarounds

expand the if condition
```
if (feature switch)
else
{
if (runtime check)
else
}
```

### Configuration

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.