Skip to content

Add a null forgiving operator#9585

Merged
jeskew merged 5 commits intomainfrom
jeskew/null-forgiving-operator
Jan 19, 2023
Merged

Add a null forgiving operator#9585
jeskew merged 5 commits intomainfrom
jeskew/null-forgiving-operator

Conversation

@jeskew
Copy link
Copy Markdown
Contributor

@jeskew jeskew commented Jan 19, 2023

Resolves #9565

This PR adds a postfix ! operator that asserts that a given value is not null, which transforms the assigned type of the value from null | <type> to just <type>.

Microsoft Reviewers: Open in CodeFlow

@jeskew jeskew requested a review from a team January 19, 2023 18:25
continue;
}

if (this.Check(TokenType.Exclamation))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Exclamation

Can you also update our pseudo grammar file?

@majastrz
Copy link
Copy Markdown
Member

memberExpression ->

Can you also add some parser unit tests to ensure that the new operator associativity is as we expect?


Refers to: docs/grammar.md:88 in 0d972f7. [](commit_id = 0d972f7, deletion_comment = False)

'|');
}

[TestMethod]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TestMethod

Should we also update some of the baseline tests to add the new operator?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added a usage to the TypeDeclarations_LF baseline (mostly because an array of a union type is the easiest way to trigger a nullable type prior to #9533 or #9454 landing), and it looks like one of the invalid expressions from InvalidExpressions_LF is now valid (at least at a syntactic level).

Copy link
Copy Markdown
Member

@majastrz majastrz left a comment

Choose a reason for hiding this comment

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

:shipit:

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-null assertion function or operator

2 participants