Roslyn: Compiler warning for nullability attributes strings not matching parameter names

Created on 14 May 2020  路  4Comments  路  Source: dotnet/roslyn

Feature request:
I'm finding the following attribute extremely error-prone, because we can't use nameof(...) in an attribute referring to a parameter in a method. If I mistype the string, the nullability analysis will go wrong, but I will never really know.

image

It would be nice to have an analyzer that detects compiler's nullable analysis that uses this nullability attribute generate a compiler warning when parameter names do not match with the strings.

Area-Compilers Feature Request

Most helpful comment

This seems like it should really be a compiler warning. The compiler is doing the analysis and interpreting this attribute; if it's given something that doesn't make sense and it can't apply the intent of the developer, it should warn.
cc: @jcouv

All 4 comments

Seems related to: https://github.com/dotnet/runtime/issues/33763

@buyaa-n @jeffhandley @bartonjs @stephentoub

dotnet/runtime#33763 is only for ArgumentException and its descendants constructor overloads having parameter of string. Assume this should apply for any class for any method with any ref type parameters having this attribute

Not sure if this can be added to the nullability analyzer itself, that seems more convenient to me, if that possible

This seems like it should really be a compiler warning. The compiler is doing the analysis and interpreting this attribute; if it's given something that doesn't make sense and it can't apply the intent of the developer, it should warn.
cc: @jcouv

@stephentoub that would be even better!

Was this page helpful?
0 / 5 - 0 ratings