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.96k stars 4.03k forks source link

C# Interactive allows illegal shadowing within a single statement #16523

Open aluanhaddad opened 7 years ago

aluanhaddad commented 7 years ago

Version Used: Visual C# 2017 RC 00369-50000-00000-AA881 Steps to Reproduce:

  1. Open the C# Interactive Window and enter
    var task = Task.Run(() => 1).ContinueWith(task => task.Result);

Expected Behavior An error is reported

A local or parameter named 'task' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter

Actual Behavior: The code compiles and executes.

gafter commented 7 years ago

This may not be a bug; the "enclosing" symbol is a field, not a local.

jnm2 commented 7 years ago

This may not be a bug; the "enclosing" symbol is a field, not a local.

Something about this bothers me deeply. As far as the C# scripting language spec is concerned, that should stay an implementation detail, shouldn't it?

tmat commented 7 years ago

Yes, the fact that the script variable is backed by a field is an implementation detail. However, we may chose to allow this shadowing. Note that the C# scripting language spec doesn't exist yet.

jnm2 commented 7 years ago

Note that the C# scripting language spec doesn't exist yet.

Which is why I brought it up- since we're deviating from the C# language a bit, we will want one 😄

aluanhaddad commented 7 years ago

Also, the scripting language interfaces directly with Visual Studio projects and there are commands like send to interactive. It would be best for the language semantics to be as 1 to 1 as possible