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
PlatformInterface._instanceToken
needs reworking due to an upcoming dart language change
#109339
Comments
I believe you're talking about this class here, which is from the I don't actually have too much context about how this class is used. Maybe @stuartmorgan or someone from his team can help out? |
You're right, thanks. Edited the issue to clarify. |
Summarizing from discussion elsewhere since I was confused about this: the key functionality of So it's already the case that the behavior doesn't match the documentation, and the difference will only ever affect tests since the whole point here is that this is to prevent people from shipping code that uses But we should match the documented behavior (and provide the better error message that our own assertion error contains), so changing to an Expando seems reasonable to me. |
Currently, in some circumstances where a subclasses of `PlatformInterface` erroneously uses `implements` rather than `extends`, a `NoSuchMethodError` will be thrown (in spite of the documentation at https://pub.dev/documentation/plugin_platform_interface/latest/plugin_platform_interface/PlatformInterface/verify.html claiming that `AssertionError` will be thrown). After flutter/flutter#109339 is fixed, the correct type of exception will be thrown. To avoid a test breakage in `platform_interface_firebase_core_test.dart` when the fix happens, we need to modify the test so that it doesn't care what kind of exception is thrown.
Currently, in some circumstances where a subclasses of `PlatformInterface` erroneously uses `implements` rather than `extends`, a `NoSuchMethodError` will be thrown (in spite of the documentation at https://pub.dev/documentation/plugin_platform_interface/latest/plugin_platform_interface/PlatformInterface/verify.html claiming that `AssertionError` will be thrown). After flutter/flutter#109339 is fixed, the correct type of exception will be thrown. To avoid a test breakage in `geocoding_platform_interface_test.dart` when the fix happens, we need to modify the test so that it doesn't care what kind of exception is thrown.
Currently, in some circumstances where a subclasses of `PlatformInterface` erroneously uses `implements` rather than `extends`, a `NoSuchMethodError` will be thrown (in spite of the documentation at https://pub.dev/documentation/plugin_platform_interface/latest/plugin_platform_interface/PlatformInterface/verify.html claiming that `AssertionError` will be thrown). After flutter/flutter#109339 is fixed, the correct type of exception will be thrown. To avoid a test breakage in `geolocator_platform_interface_test.dart` when the fix happens, we need to modify the test so that it doesn't care what kind of exception is thrown.
Currently, in some circumstances where a subclasses of `PlatformInterface` erroneously uses `implements` rather than `extends`, a `NoSuchMethodError` will be thrown (in spite of the documentation at https://pub.dev/documentation/plugin_platform_interface/latest/plugin_platform_interface/PlatformInterface/verify.html claiming that `AssertionError` will be thrown). After flutter/flutter#109339 is fixed, the correct type of exception will be thrown. To avoid tests breakages when the fix happens, we need to modify these tests so that they don't care what kind of exception is thrown.
Currently, in some circumstances where a subclasses of `PlatformInterface` erroneously uses `implements` rather than `extends`, a `NoSuchMethodError` will be thrown (in spite of the documentation at https://pub.dev/documentation/plugin_platform_interface/latest/plugin_platform_interface/PlatformInterface/verify.html claiming that `AssertionError` will be thrown). After flutter/flutter#109339 is fixed, the correct type of exception will be thrown. To avoid tests breakages when the fix happens, we need to modify these tests so that they don't care what kind of exception is thrown.
Currently, in some circumstances where a subclasses of `PlatformInterface` erroneously uses `implements` rather than `extends`, a `NoSuchMethodError` will be thrown (in spite of the documentation at https://pub.dev/documentation/plugin_platform_interface/latest/plugin_platform_interface/PlatformInterface/verify.html claiming that `AssertionError` will be thrown). After flutter/flutter#109339 is fixed, the correct type of exception will be thrown. To avoid a test breakage in `geolocator_platform_interface_test.dart` when the fix happens, we need to modify the test so that it doesn't care what kind of exception is thrown.
Currently, in some circumstances where a subclasses of `PlatformInterface` erroneously uses `implements` rather than `extends`, a `NoSuchMethodError` will be thrown (in spite of the documentation at https://pub.dev/documentation/plugin_platform_interface/latest/plugin_platform_interface/PlatformInterface/verify.html claiming that `AssertionError` will be thrown). After flutter/flutter#109339 is fixed, the correct type of exception will be thrown. To avoid tests breakages when the fix happens, we need to modify these tests so that they don't care what kind of exception is thrown.
Currently, in some circumstances where a subclasses of `PlatformInterface` erroneously uses `implements` rather than `extends`, a `NoSuchMethodError` will be thrown (in spite of the documentation at https://pub.dev/documentation/plugin_platform_interface/latest/plugin_platform_interface/PlatformInterface/verify.html claiming that `AssertionError` will be thrown). After flutter/flutter#109339 is fixed, the correct type of exception will be thrown. To avoid a test breakage in `geocoding_platform_interface_test.dart` when the fix happens, we need to modify the test so that it doesn't care what kind of exception is thrown.
Currently, in some circumstances where a subclasses of `PlatformInterface` erroneously uses `implements` rather than `extends`, a `NoSuchMethodError` will be thrown (in spite of the documentation at https://pub.dev/documentation/plugin_platform_interface/latest/plugin_platform_interface/PlatformInterface/verify.html claiming that `AssertionError` will be thrown). After flutter/flutter#109339 is fixed, the correct type of exception will be thrown. To avoid tests breakages when the fix happens, we need to modify these tests so that they don't care what kind of exception is thrown.
This change replaces `PlatformInterface._instanceToken` (an instance field that points from a `PlatformInterface` to its corresponding token) with an expando that maps from `PlatformInterface` to `Object`. There is no change to the public API, and no change to the behavior of users' production code. This change ensures that if a customer tries to implement `PlatformInterface` using `implements` rather than `extends`, the code in `PlatformInterface._verify` won't try to access the private `_instanceToken` field in `PlatformInterface`. This is important because an upcoming change to the dart language is going to cause such accesses to throw exceptions rather than deferring to `noSuchMethod` (see dart-lang/language#2020 for details). Fixes flutter/flutter#109339.
… to an expando. (#6411) This change replaces `PlatformInterface._instanceToken` (an instance field that points from a `PlatformInterface` to its corresponding token) with an expando that maps from `PlatformInterface` to `Object`. There is no change to the public API, and no change to the behavior of users' production code. This change ensures that if a customer tries to implement `PlatformInterface` using `implements` rather than `extends`, the code in `PlatformInterface._verify` won't try to access the private `_instanceToken` field in `PlatformInterface`. This is important because an upcoming change to the dart language is going to cause such accesses to throw exceptions rather than deferring to `noSuchMethod` (see dart-lang/language#2020 for details). Fixes flutter/flutter#109339.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
… to an expando. (flutter#6411) This change replaces `PlatformInterface._instanceToken` (an instance field that points from a `PlatformInterface` to its corresponding token) with an expando that maps from `PlatformInterface` to `Object`. There is no change to the public API, and no change to the behavior of users' production code. This change ensures that if a customer tries to implement `PlatformInterface` using `implements` rather than `extends`, the code in `PlatformInterface._verify` won't try to access the private `_instanceToken` field in `PlatformInterface`. This is important because an upcoming change to the dart language is going to cause such accesses to throw exceptions rather than deferring to `noSuchMethod` (see dart-lang/language#2020 for details). Fixes flutter/flutter#109339.
… to an expando. (flutter#6411) This change replaces `PlatformInterface._instanceToken` (an instance field that points from a `PlatformInterface` to its corresponding token) with an expando that maps from `PlatformInterface` to `Object`. There is no change to the public API, and no change to the behavior of users' production code. This change ensures that if a customer tries to implement `PlatformInterface` using `implements` rather than `extends`, the code in `PlatformInterface._verify` won't try to access the private `_instanceToken` field in `PlatformInterface`. This is important because an upcoming change to the dart language is going to cause such accesses to throw exceptions rather than deferring to `noSuchMethod` (see dart-lang/language#2020 for details). Fixes flutter/flutter#109339.
… to an expando. (flutter#6411) This change replaces `PlatformInterface._instanceToken` (an instance field that points from a `PlatformInterface` to its corresponding token) with an expando that maps from `PlatformInterface` to `Object`. There is no change to the public API, and no change to the behavior of users' production code. This change ensures that if a customer tries to implement `PlatformInterface` using `implements` rather than `extends`, the code in `PlatformInterface._verify` won't try to access the private `_instanceToken` field in `PlatformInterface`. This is important because an upcoming change to the dart language is going to cause such accesses to throw exceptions rather than deferring to `noSuchMethod` (see dart-lang/language#2020 for details). Fixes flutter/flutter#109339.
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 theplugin_platform_interface
package), which insists that it be subclassed by clients viaextends
rather thanimplements
, 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 ofnoSuchMethod
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 thatPlatformInterface
will be able to reliably detect whether it is subclassed byextends
orimplements
, 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 standardObject.noSuchMethod
method, and thus expect aNoSuchMethodError
to be thrown. ChangingPlatformInterface._instanceToken
to use an expando will prevent theNoSuchMethodError
from occurring, and insteadPlatformInterface._verify
will throw anAssertionError
. 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
.The text was updated successfully, but these errors were encountered: