How to define overridden variables or shaded variables

When using the same variable twice in the same area with the F # compiler, there is no warning or feedback. eg.

let s = "abc" let s = "def" printfn "%A" s 

leads to

 def 

I have seen
Is there a way to get warnings about shadowing values ​​in F # in Visual Studio?
F # value shading - is it possible to disable value shading within the same area

Is there a way to get feedback on shaded variables, either using a compiler warning, or visually in an editor. How can I do that?

+7
f # shadowing
source share
1 answer

Firstly, the shadowing of variables in one area is not an error or something that should be disabled. As Joel Muller claims to be legitimate, useful, and common .

Per MSDN

At any level of visibility, except for the module area, it is not an error to reuse the value or function name. If you reuse the name, the declared name is later shadowed by the name previously declared.


Syntax Coloring Function for Visual Studio F # Power Extension Tools will display the current valid variable and show shaded variables as light gray. eg.

enter image description here

The extension can be installed from the Visual Studio menu.

Tools β†’ Extensions and Updates
As soon as the Select Visual Studio Gallery dialog box opens
In the upper right search box, type F # Power Tools
Since I already installed it, the installation option is not displayed.

enter image description here

This feature can be activated from the Visual Studio menu.

Tools β†’ Options β†’ F # Power Tools β†’ General β†’ Coloring Syntax β†’ Gray Unused Ads

enter image description here

With the option turned off:

enter image description here

with option:

enter image description here

Note. After changing the option, the source file must be closed and then opened again for the changes to take effect. For this, Visual Studio does not need to be restarted, but it will have the same effect.

Thanks to Ringil for notifying me of my previously invalid statement.

Note from source:

Delete unused ads


Unused non-public types, methods, functions and values ​​are currently being checked. Beware that this function is 100% reliable when the code does not have a type error. This setting is available in the general options. By default, it is disabled because there may be performance issues with large files.

F # Power Tool Functions List

+9
source share

All Articles