dotnet / dotnet/roslyn

Quick Info shows wrong types when using Multiple Global Aliases for the same type

Open
#82,935 6 comments 1 reaction 0 assignees View on GitHub
Area-IDE
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

**Version Used**: 10.0.103

**Steps to Reproduce**:

[Runnable repro](https://lab.razor.fyi/#nVLBihNBFGRFFp2T-AV1UyHMkuwtcRdERVcElQQET3Z6XmYedl7Hft3Jzv_4M_6CIJ69-gXSPUEI7qp4mcN79aqqq6b6flxVr4Nvg1nXVu9-OW6dXxqHpCwtFv2GxjiDxsDSzqrflpM_LU9xBpY4q4bRvNdI6_qxd45sZC9aPyOhwHZWVScneO63FFA-sSNsTWCzdAQxa1KwlOnKO-d3mc6xkCJ6KFFZfUxsP4Bl5evC9_RyQzZSM8UTLnom9A_Li0aD9_OMemRjMu46zPi8uu540LuQlZ93fqdlt9ixpQvRSKZ5tRpG-5SEdvcfzP5qbAjzf53tr__R2rygD70tOgoEEwgTsGoiRcdNQ4K8mGbIeJpReFPiziLQrDJUPgJtKVflU9uVWmK_ITRknQmmtI6kpc9Y7_8S7XxyDcRHbJzpYRC8oyJYZ8HJFC9ZCKdQ0ytiZ-L-0hrBkhBo7bfUYEnWJCVwvKeFLik1IyxTPHCbSTii8aSFH8Dbjm1X6AYG62WVlL3UV6TMEq-OOHs6jPhC4q98X9yw-u72rR-fv3391N65-f7o8ugn).

```csharp
global using Type1 = string;
global using Type2 = string;
global using Type3 = int;
using System.Collections.Generic;

// Hover over the variable names in the following lines to see the quick info.
// This can be reproduced in lab.razor.fyi, VSCode, Visual Studio, etc...

// Expected: Dictionary
// Actual: Dictionary
Dictionary quickInfoShowsType1TwiceInsteadOfType1Type2 = new();

// Expected: Dictionary
// Actual: Dictionary
Dictionary quickInfoShowsType1TwiceInsteadOfType1String = new();

// There are 2 issues hidden here:
// 1: The Quick Info shows Type3, even though the type declarations uses int. Type3 should not play a role here.
// 2: Line 3 says that Type3 can be removed because it's not used, but Quick Info says it does.
// Which can cause confusion.
Dictionary quickInfoShowsType1Type3InsteadOfType1Int = new();
```

**Diagnostic Id**: None

**Expected Behavior**: Quick Info should match the declared types

**Actual Behavior**: Quick Info reuses global aliases (Example 1 and 2), and even PREFERS using Type3 over int (example 3) even though I didn't ask for this (which is wild to me).

**Extra information**:
My use case for this was to add more meaning to a `Dictionary AmountWithPrice`. There was confusion about the key being Amount or Price, because they shared the same type.

Technically, I _should_ create value objects to obtain meaning AND compile time safety (`record Amount`, `record Price`) , but in this scenario that safety wasn't needed.

The team members got confused when they looked at the Quick Info and wrong types were shown.

This was discussed with @jnm2 and @jcouv at the MVP Summit :)

Contributor guide

Open the contributing guide

Research direction

Start by running the linked repro and comparing Quick Info with the declared generic types and global aliases. No source file or test is named, so trace the Roslyn Quick Info path that formats these types. Done means Quick Info matches the declaration and does not incorrectly treat unused aliases as referenced.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
compilers, developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.