Skip to content

Add exception about extension members in error about nullable receivers #4318

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion accepted/2.12/nnbd/feature-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Status: Draft

## CHANGELOG

2025.04.03
- Add an exception for extension members in the error about nullable
receivers.

2021.07.28
- Allow a constant factory constructor in a class with a late final instance
variable.
Expand Down Expand Up @@ -531,7 +535,7 @@ location outside of the statement.

It is an error to call a method, setter, getter or operator on an expression
whose type is potentially nullable and not `dynamic`, except for the methods,
setters, getters, and operators on `Object`.
setters, getters, and operators on `Object`, and except for extension members.
Copy link
Member

Choose a reason for hiding this comment

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

(Does "extension members" include extension type members, because you are allowed to call those on an extension type which doesn't implement Object.)

Probably correct and good fix, but still indirect.

What would happen if we remove this paragraph entirely?

I feel like it should fall through to some rule that says that you can't call somethin which isn't there, and where there is also no extension member. That is, a member invocation would do a lookup on the static type to see if there is a member. If so, see if it's compatible. If not, check for applicable extension functions. If not one such, it's an error.

If not having this paragraph would err out missing something which says which members T? has, then that's what we should write:

A type of the form T? has only the same members as Object, with the same signatures.

Then it's just an error to call a member that a type doesn't have, as usual.


It is an error to read a field or tear off a method from an expression whose
type is potentially nullable and not `dynamic`, except for the methods and
Expand Down