Skip to content

Use explicit type instead of 'var' emitted on enum value assignment #75289

Open
@just-ero

Description

@just-ero

Version Used

Compiler: 4.12.0-3.24470.4 (d799b05)
.NET: 9.0.100-rc.1.24452.12
Visual Studio Code: 1.93.1, 38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40, x64
C# Extension: v2.49.25
C# Dev Kit Extension: v1.11.11

Steps to Reproduce

  1. Create or open a C# project in Visual Studio Code (Visual Studio untested).
  2. Set or add the following properties to an .editorconfig file that applies to the project:
    csharp_style_var_elsewhere             = false:suggestion
    csharp_style_var_when_type_is_apparent = true:suggestion
    
  3. Add the following code wherever syntactically applicable:
    var e = E.A;
    enum E { A }
  4. Observe the suggestion Use explicit type instead of 'var' (IDE0008) on the var keyword.

Expected Behavior

The suggestion is not emitted, as the type is quite apparent.

Actual Behavior

The suggestion is emitted.

The suggestion is not emitted for these snippets:

var e = default(E);
var e = new E();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions