Skip to content

PlatformInterface._instanceToken needs reworking due to an upcoming dart language change #109339

@stereotype441

Description

@stereotype441

The dart language team will soon be changing the behavior of the language so that an invocation of a private class members won't get dispatched to a noSuchMethod method in another library; instead an exception will be thrown. This is a necessary prerequisite to allowing promotion of private fields (dart-lang/language#2020). It also closes an important privacy loophole in the language, by ensuring that the user can see all the possible behaviors of a private member invocation without having to look outside of the library.

This has an important consequence for PlatformInterface (from the plugin_platform_interface package), which insists that it be subclassed by clients via extends rather than implements, and detects the difference by reading from the private field _instanceToken and checking whether the expected value was returned. Today, that technique works some of the time (it relies on the implementing class having an implementation of noSuchMethod that completes without throwing an exception), but after the upcoming language change it will always throw a yet-to-be-defined exception.

I believe we should change PlatformInterface._instanceToken to use an expando (similar to what was done in #109238), so that PlatformInterface will be able to reliably detect whether it is subclassed by extends or implements, both before and after the upcoming language change.

In the process we'll also need to update several brittle tests that rely on the invocation of _instanceToken being dispatched to the standard Object.noSuchMethod method, and thus expect a NoSuchMethodError to be thrown. Changing PlatformInterface._instanceToken to use an expando will prevent the NoSuchMethodError from occurring, and instead PlatformInterface._verify will throw an AssertionError. These tests need to be updated so that they don't care what particular kind of exception is thrown. The tests I've found that require fixing are in the following repos:

To avoid breakages, I'll submit PRs to these repos before landing the change to PlatformInterface.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listpackageflutter/packages repository. See also p: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions