Target-typed expressions with nested elements/branches don't get converted when one of nested expressions is directly an error
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
Discovered in https://github.com/dotnet/roslyn/pull/80907
**Steps to Reproduce**:
```cs
class C
{
public void M(bool b, int i)
{
C[] cs = [a, default];
C c1 = b ? a : default;
C c2 = i switch
{
1 => a,
_ => default,
};
(C, int) t = (a, default);
}
}
```
Hover over `default` literal in each expression
**Expected Behavior**:
I get type information about the literal
**Actual Behavior**:
Nothing is shown
**Breakdown:**
The underlying issue lies in the compiler layer. Althouth in each case target type can be determined, expressions don't get converted to it due to one of nested elements/expressions being directly an error. If an error isn't directly in the element/branch, e.g. if I change collection expression to `[new(a), default]` even though the first element still contains an error, types start to flow through, so I get correct type information both on `new` and `default`. The same applies to other examples as well.
There is theoretical IDE impact, but I believe it is extreamly rare to see it in practical applications
Contributor guide
Research direction
No source files, tests, or entry points are named. Start by reproducing the collection, conditional, switch, and tuple examples in Roslyn and tracing compiler target-type conversion when a nested expression is a direct error. Done means hovering over each default literal provides the expected type information.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100