Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Draft
jnm2 wants to merge3 commits intodraft-v8
base:draft-v8
Choose a base branch
Loading
fromjnm2/arrays_of_nrt

Conversation

jnm2
Copy link
Contributor

No description provided.

| interface_type
| delegate_type
| 'dynamic'
| (class_type | interface_type | delegate_type | 'dynamic') nullable_type_annotation?
Copy link
ContributorAuthor

@jnm2jnm2May 31, 2025
edited
Loading

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
Copy link
ContributorAuthor

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.
Copy link
Contributor

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.

Copy link
ContributorAuthor

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)

Copy link
Contributor

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.

Comment on lines +5 to +10
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
Copy link
ContributorAuthor

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?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@Nigel-EcmaNigel-EcmaNigel-Ecma left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@jnm2@Nigel-Ecma@gafter

[8]ページ先頭

©2009-2025 Movatter.jp