Coder Social home page Coder Social logo

Comments (6)

meziantou avatar meziantou commented on June 12, 2024 1

Default values should be handled correctly. It looks like a bug, I'll have a look at it soon.

from meziantou.analyzer.

meziantou avatar meziantou commented on June 12, 2024 1

I can repro on Roslyn 4.4 and before, but it's fine on 4.5 (latest).
I will investigate later. As a workaround, you can update VS or the .NET SDK.

from meziantou.analyzer.

meziantou avatar meziantou commented on June 12, 2024

I cloned your project, but I do not get any MA0099. Just to be sure I added dotnet_diagnostic.MA0099.severity = error and run dotnet build.

Could you try to create a simple repro?

from meziantou.analyzer.

erri120 avatar erri120 commented on June 12, 2024

https://sharplab.io/#v2:C4LghgzsA0AmIGoA+ABATARgLAChcDswBbAUwgAcwBjEgAgFkSAvASzH2AHsBXAOgEFCAGwCeTEgCde9fgAZZATgUBuXLhQBmWiXzciDEQFFdRXAG9ctK7QBynfHQC8tWdEvWAyp1K1nGNzgAvmo4ANr8wMASLABG3MAkAKoQYADmJAAUEVGx8SQAKmAS6cAQAkJCAJQAuupa6AbZ0XEJtCC0TbkJ5u5Wmo2RzXkZ9EYmtDFFvgbGerx2DpW0ZrTBQSGho50tJNW0APT7tADuRfgs+Knt3BB0hgAe5EIsVCzA2uMAbmBC3HQAZpwJLQAOSjWZEEG0C5QEhgWC0Tj/Fx1WgNUYAYSEkAgPRw1jRWkx2IgEBGYz0tEBnGm4JM83sJCWKzWvUJaIwADYDFicbQMRI4QkMpU2RZ8QTrCgAOy0BzHHkksmVZQHI74GmnCTnS5staBIA==

public enum MyEnum
{
    None = 0,
    Some = 1,
}

[AttributeUsage(AttributeTargets.All)]
public class MyAttribute : Attribute
{
    public MyAttribute(MyEnum bar = MyEnum.None) { }
}

[MyAttribute] // warning: use Explicit enum value for 'MyEnum' instead of 0
public class MyClass
{
    public MyClass(MyEnum foo = MyEnum.None) { }

    public static MyClass Create()
    {
        return new MyClass(); // no warning
    }
}

I've tried various combinations, but only default values in attributes seem to trigger this warning.

from meziantou.analyzer.

meziantou avatar meziantou commented on June 12, 2024

Which version of Roslyn and which language version do you use?
You can use #error version to get the information. See Getting Roslyn (C# compiler) and Language versions for more info.

from meziantou.analyzer.

erri120 avatar erri120 commented on June 12, 2024

Which version of Roslyn and which language version do you use? You can use #error version to get the information. See Getting Roslyn (C# compiler) and Language versions for more info.

Compiler version: '4.4.0-6.23068.5 (0760f14e)'. Language version: 11.0.

dotnet --info output:

.NET SDK:
 Version:   7.0.103
 Commit:    276c71d299

Runtime Environment:
 OS Name:     arch
 OS Version:
 OS Platform: Linux
 RID:         arch-x64
 Base Path:   /usr/share/dotnet/sdk/7.0.103/

Host:
  Version:      7.0.3
  Architecture: x64
  Commit:       0a2bda10e8

.NET SDKs installed:
  6.0.114 [/usr/share/dotnet/sdk]
  7.0.103 [/usr/share/dotnet/sdk]

from meziantou.analyzer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.