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
{{ message }}
Repository navigation
NullabilityInfoContext does not properly respect CodeAnalysis attribute on indexer property #63849
In most cases code analysis attributes like AllowNull are respected, but this is not true for indexer properties.
Reproduction Steps
publicvoidMain(){varcontext=newNullabilityInfoContext();varindexerInfo=context.Create(typeof(HasIndexer).GetProperty("Item")!);Console.WriteLine(indexerInfo.WriteState);// NotNull (should be Nullable)}publicclassHasIndexer{[AllowNull]publicstringthis[string?s]{get=>default!;set{}}}
Expected behavior
The write state should be nullable because the following compiles without warnings:
new HasIndexer()["a"] = null;
Actual behavior
Write state is not null as if the attribute were not present.
Regression?
No response
Known Workarounds
No response
Configuration
VS 17.0.2, .NET 6, Windows 10 x64.
I don't have any reason to believe this is configuration specific.
Activity
danmoseley commentedon Jan 17, 2022
Thanks for opening these nullable annotation bugs @madelson . Are you interested in offering a PR for any of them?
madelson commentedon Jan 17, 2022
@danmoseley yes I'm working on fixes for some of them with the idea of sending a PR.
Fix several bugs in NullabilityInfoContext.