Skip to content

Describe the impact of ? on arrays of arrays#1554

Open
jskeet wants to merge 9 commits intodraft-v8from
multi-dimensional-arrays
Open

Describe the impact of ? on arrays of arrays#1554
jskeet wants to merge 9 commits intodraft-v8from
multi-dimensional-arrays

Conversation

@jskeet
Copy link
Contributor

@jskeet jskeet commented Jan 27, 2026

Alternative to #1386.

Fixes #1385.

@jskeet
Copy link
Contributor Author

jskeet commented Jan 27, 2026

I'm fully expecting there to be some more work here, but I'm hoping it's at least close.

@jskeet jskeet added the meeting: discuss This issue should be discussed at the next TC49-TG2 meeting label Jan 27, 2026
@jskeet
Copy link
Contributor Author

jskeet commented Jan 27, 2026

@Nigel-Ecma: I believe the grammar test failure is now a matter of changing the expected tokens (due to the introduction of non_array_non_nullable_type) - let me know if this is something I can fix myself, or whether it needs your help :)

Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach. I have a couple comments to consider and discuss.

Copy link
Contributor

@Nigel-Ecma Nigel-Ecma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve made a few comments but obviously there is a fair bit to go yet – e.g. conversions. Some of it is still confusing, but it seems a good start to dressing this up ;-)

@Nigel-Ecma
Copy link
Contributor

@Nigel-Ecma: I believe the grammar test failure is now a matter of changing the expected tokens (due to the introduction of non_array_non_nullable_type) - let me know if this is something I can fix myself, or whether it needs your help :)

With the proviso that I haven’t downloaded this and run the failing tests it does look like the errors reported are valid changes in the expect parse due to the revised grammar.

If this is the case then it will just need a few updates to the “reference” parse files (the ones that are machine generated and ignored in PR reviews). You can generate them yourself but you might prefer one of us with the tools already downloaded to run and produce them does it! It can wait until the PR is approved and before it is merged.

jskeet and others added 2 commits February 11, 2026 20:50
Co-authored-by: Nigel-Ecma <6654683+Nigel-Ecma@users.noreply.github.com>
@jskeet
Copy link
Contributor Author

jskeet commented Feb 11, 2026

Next steps:

  • Nigel to email Jon the files to add to this PR to get the grammar checker passing
  • Jon will update this PR, then merge.
  • Jon to file a new issue around mapping between nullable and non-nullable arrays, see Allow arrays of nullable reference types #1386, to also include conversions - and anything else folks think is missing
  • Jon will hopefully create a new PR to address that

Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's :shipit: based on our discussion in the meeting.

@BillWagner BillWagner dismissed Nigel-Ecma’s stale review February 11, 2026 21:21

Per meeting discussion

Copy link
Contributor

@jnm2 jnm2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this approach!

;

non_array_non_nullable_type
: value_type
Copy link
Contributor

@Nigel-Ecma Nigel-Ecma Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing grammar supported T?[] iff T was a value type, this PR intends to extend it to all T. The existing grammar supported this as value_type covers both nullable & non-nullable value types – the only nullable types that existed at the time. The revised grammar here provides two ways that non_array_type can parse V? as shown below – text in brackets, e.g. [?], following a rule indicates the input token(s) it is matching:

non_array_type ➜ non_array_non_nullable_type nullable_type_annotation? [`?`]
    non_array_non_nullable_type ➜ value_type
                                ➜ non_nullable_value_type  [`V`]

or

non_array_type ➜ non_array_non_nullable_type nullable_type_annotation?
    non_array_non_nullable_type ➜ value_type
                                ➜ nullable_value_type
                                ➜ non_nullable_value_type [`V`] nullable_type_annotation [`?`]

As there are two parses the new grammar is ambiguous, but I suspect ambiguity was not intended and this needs to be fixed in the grammar and not with a prose disambiguation rule.

Changing line 67 to reference non_nullable_value_type would seem to fixed the immediate issue, but I have not worked that through the PR’s total grammar changes myself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That didn't take me as long to understand as I feared - and thank you for the suggestion, which I've applied. Fortunately the name of the rule is pretty clear in terms of what it's trying to convey, too.

@BillWagner please could you check that you're happy with the change on this line as well? (value_type => non_nullable_value_type). I suspect we'll still need Nigel to run the grammar checker etc, but hopefully this will have cleared up the ambiguity.

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

Labels

meeting: discuss This issue should be discussed at the next TC49-TG2 meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Arrays of nullable references

4 participants