-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MaybeNullAttribute not working #36986
Labels
Milestone
Comments
I think this example should not warn: #nullable enable
using System.Diagnostics.CodeAnalysis;
namespace System.Diagnostics.CodeAnalysis
{
class MaybeNullAttribute : System.Attribute { }
}
public class C {
[return: MaybeNull]
public T M<T>(object? o) {
return (T)o; // gives warning CS8601, but probably shouldn't
}
} /cc @jcouv |
This also shouldn't warn: public class C {
[return: MaybeNull]
public T M<T>() {
return default;
}
} |
Thanks for reporting this. |
What should I do in this situation? Suppress CS8601? |
Use the suppression operator. For example: |
mavasani
added a commit
to mavasani/roslyn
that referenced
this issue
Dec 11, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
I'm converting Newtonsoft.Json to use nullable types and I can't get
MaybeNullAttribute
to work. My remaining warnings are related to generic types.Note that I have many old targets so I'm using internal nullable attributes (located in NullableAttributes.cs).
NotNullAttribute
andNotNullWhenAttribute
work fine, but I can't getMaybeNullAttribute
to work. I've tried it inSystem.Runtime.CompilerServices
andSystem.Diagnostics.CodeAnalysis
namespaces with no result.Version Used: VS2019 + Microsoft.Net.Compilers.Toolset=3.2.0-beta3-final
Steps to Reproduce:
Expected Behavior:
There should not be a nullable warning because
[return: MaybeNull]
is on the return type.Actual Behavior:
There is a warning casting
object?
toT
.The text was updated successfully, but these errors were encountered: