Emit nullable annotations for c# 8.0
Currently antlr generates nullable attributes to indicate nullability when targeting C#.
It would be extremely useful if there was an option to emit C# 8.0 nullable annotations instead.
@sharwell
I wonder if you have any thoughts on how difficult this would be to cover completely? I imagine the first step would be to cover the nuget packages with nullable annotations - I'm happy to do that, but I don't know if I have enough time to add an option to emit nullable annotations.
@YairHalberstadt I'm planning to update tunnelvisionlabs/antlr4cs using the nullability infrastructure we created for tunnelvisionlabs/antlr4ts.
Does the issue https://github.com/antlr/antlr4/issues/1972 influence this one? There is no distinction between missing token due to the optional operator (?) and due to a syntax error.
@KvanTTT That issue impacts the usability of the syntax tree when errors occur, including but not limited to languages that represent null in the type system.
@sharwell, can I please just double-check the latest state of this issue? Am I right in saying that currently generated C# code will not distinguish between a value which might be null and which might not (according to the grammar schema)? i.e. the generated C# will always say something like public SomeContext someThing; and never public SomeContext? someThing;. That's what I'm seeing on my system, but not sure if I'm just doing something wrong. Thanks!
Am I right in saying that currently generated C# code will not distinguish between a value which might be null and which might not (according to the grammar schema)?
Yes, that's right.
Cool, thanks!
If nullable annotations are implemented maybe it will make sense to use the newest C# version for other constructions or at least C# 8.0? For instance, expression bodies for single-line properties. Also, it will make sense to remove Obsolete properties since grammar will be not backward compatible.
Yes please! This is a necessity! Unfortunately C# is not very pedantic with warnings when using unclear nullability methods in a file with nullable enabled. I wish there was a pedantic mode that would treat unclear nullability as nullable, so I'd have to explicitly check null or assert non-null myself. Since it's not like this, it's very confusing to have mixed nullability, cause I never know when I have a guarantee or not.
Yes please! This is a necessity! Unfortunately C# is not very pedantic with warnings when using unclear nullability methods in a file with nullable enabled. I wish there was a pedantic mode that would treat unclear nullability as nullable, so I'd have to explicitly check null or assert non-null myself. Since it's not like this, it's very confusing to have mixed nullability, cause I never know when I have a guarantee or not.
I totally agree. The nullable reference types in C# are basically a preview feature that got released. So many things broken with them.