Uh oh!
There was an error while loading. Please reload this page.
Remove compiler downgrade - #32474
Conversation
ViktorHofer
commented
Feb 18, 2020
@safern would you mind pushing the necessary nullability fixes into this branch? |
safern
commented
Feb 18, 2020
Of course. Working on it. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| { | ||
| string key = GetKeyName(enumerator.Current.Key, ref state, options); | ||
| writer.WritePropertyName(key); | ||
| Debug.Assert(enumerator.Current.Value != null); |
There was a problem hiding this comment.
I believe this assert is incorrect and will fail with this, so consider just using null-forgiving (!).
[Fact]publicstaticvoidWriteDictionaryNullValue(){varinput=newDictionary<string,string>{{"a",null},{"b","foo"}};stringjson=JsonSerializer.Serialize(input);}Since this is calling the built-in JsonConverter<string?>, null is allowed and will work if passed in. The StringConverter overwrites the nullability, but I suppose it can't be expressed statically.
Is there something we can do here?
There was a problem hiding this comment.
I don't think we can do anything here. Since the converter here is declared as the abstract type, the compiler will resolve the signature that contains the DisallowNull annotation. So I think we should just use a !. I think we can't declare the converter variable type as JsonConverter<string?>, right?
There was a problem hiding this comment.
No, it has to remain generic. It just happens to be that all the Ts in the particular set of JsonConverter<T> work with null values (because our internal converters know how to deal with it).
I think, ideally, we will re-write parts of this to add special handling for null and honor the DisallowNull even internally.
There was a problem hiding this comment.
I think that would make sense. Internal usage of these APIs should overall honor the intent and what we tell our customers. It would be great if the usage of ! was lower.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
54ae3ce to
c923dceCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
c923dce to
50c206bCompareUh oh!
There was an error while loading. Please reload this page.
50c206b to
ca2e3bfCompareca2e3bf to
f2562bfCompareViktorHofer
commented
Feb 21, 2020
Thanks Santi, you are my hero :) |
Let's see what's going to crash :)