You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CA2263 propose to use generic overload for type, that doesn't satisfy overload's notnull generic type
Steps To Reproduce
publicstaticclassTestClass{publicstaticT?Test1<T>(ITest1tester){// bad suggestionreturn(T?)tester.Test(typeof(T));// CS8714: The type 'T' cannot be used as type parameter 'T' in the generic type or method 'ITest.Test<T>()'.Nullability of type argument 'T' doesn't match 'notnull' constraint.//return tester.Test<T>();}publicstaticT?Test2<T>(ITest1tester)whereT:notnull{// good suggestion//return (T?)tester.Test(typeof(T));returntester.Test<T>();}publicstaticT?Test3<T>(ITest2tester){// good, no suggestionreturn(T?)tester.Test(typeof(T));//return tester.Test<T>();}publicstaticT?Test4<T>(ITest2tester)whereT:Enum{// good suggestion//return (T?)tester.Test(typeof(T));returntester.Test<T>();}}publicinterfaceITest1{T?Test<T>()whereT:notnull;object?Test(Typetype);}publicinterfaceITest2{T?Test<T>()whereT:Enum;object?Test(Typetype);}
Expected behavior
No errors when generic constrain not satisfied
Actual behavior
Proposed code change trigger compilation error
The text was updated successfully, but these errors were encountered:
Analyzer
Diagnostic ID: CA2263:
Prefer generic overload when type is known
Analyzer source
NuGet Package: Microsoft.CodeAnalysis.NetAnalyzers
Version: 9.0.0-preview.24122.1
Describe the bug
CA2263 propose to use generic overload for type, that doesn't satisfy overload's
notnull
generic typeSteps To Reproduce
Expected behavior
No errors when generic constrain not satisfied
Actual behavior
Proposed code change trigger compilation error
The text was updated successfully, but these errors were encountered: