- Notifications
You must be signed in to change notification settings - Fork92
Experimenting with grammar for arrays of NRTs#1335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:draft-v8
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| interface_type | ||
| delegate_type | ||
| 'dynamic' | ||
| (class_type | interface_type | delegate_type | 'dynamic') nullable_type_annotation? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Was trying not to end up creating new names likenon_array_non_nullable_reference_type
andnon_array_nullable_reference_type
which don't sound like core concepts we'd want to be referencing elsewhere.
| interface_type | ||
| delegate_type | ||
| 'dynamic' | ||
| (class_type | interface_type | delegate_type | 'dynamic') nullable_type_annotation? | ||
| type_parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'm realizingnullable_reference_type
does not include type parameters unless it's via a mechanism I'm not seeing. We'd also want to be able toT?[]
whereT
is constrained to a class type.
@@ -738,6 +735,8 @@ There are two forms of nullability for reference types: | |||
The syntactic distinction between a *nullable reference type* and its corresponding *non-nullable reference type* enables a compiler to generate diagnostics. A compiler must allow the *nullable_type_annotation* as defined in [§8.2.1](types.md#821-general). The diagnostics must be limited to warnings. Neither the presence or absence of nullable annotations, nor the state of the nullable context can change the compile time or runtime behavior of a program except for changes in any diagnostic messages generated at compile time. | |||
The only exception to this general rule is that adding a nullable annotation can change the syntactic meaning of the type of an array of arrays. Specifically, a type such as `A[][,]` is an array of two-dimensional arrays. That is because the syntactic meaning of the array dimensions in the array type are read from the inside out. However, by adding a nullable annotation between the dimensions, writing `A[]?[,]`, changes the parsing and therefore syntactic meaning of the type. In this case, the element type of the array is `A[]?`. The type is now a two-dimensional array of a nullable array type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Nooo… The grammardecides the parsing, and hopefully the grammar supports thedesigned syntax and semantics. There is no “This is because…”
Something (better phrased) along the lines of “Array types containing nullable annotations after/between/before(pick the right one) ranks denote structurally different types to the syntactically similar array type without such annotations; this differs from all other uses of nullable annotations which do not change semantics.” Remember the Standard is not also a Rationale, some languages have published both but C# has not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
(this is not new in my draft, this is Gafter's commit from#1297)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@jnm2 – Good to know, I'll await your new draft.
void ArraysOfNullable() | ||
{ | ||
A[] p_1 = new A[5]; // Array of non-nullable A all elements inited to null (oops) | ||
A[]? q_1 = null; // Nullable array of non-nullable A, array inited to null | ||
A?[] r_1 = new A[5]; // Array of nullable A all elements inited to null | ||
A?[]? s_1 = null; // Nullable array of nullable A, array inited to null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@Nigel-Ecma Would you be able to show me how to work with files like this? This is from@gafter's PR and I copied it across, and I'd like to add some new cases when I work with it experimentally.
I don't yet understand what all can be done with this. The other folders appear to have had a tool run on them which generates a graphical representation of the parse. I'd like to know how to run it. Does a PR fail if the generated parse is out of date with the sample.cs file?
No description provided.