Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[shared_preferences] Prepare for change in handling of NoSuchMethod. #6318

Closed
wants to merge 2 commits into from

Conversation

stereotype441
Copy link
Contributor

@stereotype441 stereotype441 commented Aug 26, 2022

In a future release of Dart, if a class containing private members is
implemented (rather than extendeed), any attempt to invoke one of
the private members will result in a runtime error (see
dart-lang/sdk#49687). This is necessary in
order to soundly support field promotion
(dart-lang/language#2020).

The runtime error will most likely be a new exception type, not
NoSuchMethodError. So, to avoid breaking the
SharedPreferencesStorePlatform.instance setter, we need to
generalize it to consider any exception thrown by
_verifyProvidesDefaultImplementations as an indication that the
SharedPreferencesStorePlatform has been illegally implemented.

In the non-error case, _verifyProvidesDefaultImplementations does
nothing, so this generalization should be safe.

Fixes flutter/flutter#110364.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

In a future release of Dart, if a class containing private members is
*implemented* (rather than *extendeed*), any attempt to invoke one of
the private members will result in a runtime error (see
dart-lang/sdk#49687).  This is necessary in
order to soundly support field promotion
(dart-lang/language#2020).

The runtime error will most likely be a new exception type, not
`NoSuchMethodError`.  So, to avoid breaking the
`SharedPreferencesStorePlatform.instance` setter, we need to
generalize it to consider any exception thrown by
`_verifyProvidesDefaultImplementations` as an indication that the
`SharedPreferencesStorePlatform` has been illegally implemented.

In the non-error case, `_verifyProvidesDefaultImplementations` does
nothing, so this generalization should be safe.
@stuartmorgan-g
Copy link
Contributor

Per my comment in the issue, I would much rather we just do flutter/flutter#98709 to address this.

@stuartmorgan-g
Copy link
Contributor

Closing in favor of #6332

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SharedPreferencesStorePlatform expects too narrow an exception when illegally implemented
2 participants