Roslyn: C# Interactive allows illegal shadowing within a single statement

Created on 15 Jan 2017  路  5Comments  路  Source: dotnet/roslyn

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

  1. Open the C# Interactive Window and enter
    C# 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.

Area-Interactive Bug

All 5 comments

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

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?

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.

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 馃槃

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

Was this page helpful?
0 / 5 - 0 ratings