dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.77k stars 3.99k forks source link

IntelliCode-suggested completions don't escape keywords properly #74253

Open DoctorKrolic opened 3 weeks ago

DoctorKrolic commented 3 weeks ago

Version Used: Latest main

Steps to Reproduce: Given that AI is involved, I don't think there is a 100% reliable way to reproduce the bug, But I can somewhat consistently see it using the following snippet:

void M()
{
    var @params = GetParams();
    UseParams($$
}

void UseParams(MyParams @params) { }

MyParams GetParams() => new();

class MyParams
{
}

Invoke completions at $$. You will see a bug when there is a starred item at the top of the list.

Expected Behavior: Starred item is properly escaped with @.

Actual Behavior: params is not escaped, so there is a compiler error if I accept the suggestion: devenv_WvFlneZLmh However, the original completion item, which was picked by the IntelliCode is actually escaped: devenv_QFyzc6VTkD

Cosifne commented 3 weeks ago

🤔It might not related to Roslyn. E.g. Roslyn is only providing the completion structure code, the real source is from Copilot or Intellicode. Assigned to Gen for more investigation.