-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[webview_flutter_wkwebview] Remove specialization of 'map' to fix Swift warning #9810
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
base: main
Are you sure you want to change the base?
Conversation
… app to prevent a Swift warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly removes an explicit type specialization in a Swift map
call to resolve a compiler warning. I've added a couple of suggestions. One is to correct the CHANGELOG entry, as the change affects the plugin's source code, not the example app. The other, more critical suggestion is to replace try!
with try
on the modified line to prevent a potential runtime crash and properly propagate errors, aligning with the function's throwing signature.
@@ -14,7 +14,7 @@ class HTTPCookieProxyAPIDelegate: PigeonApiDelegateHTTPCookie { | |||
) throws -> HTTPCookie { | |||
let registrar = pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar | |||
|
|||
let keyValueTuples = try! properties.map<[(HTTPCookiePropertyKey, Any)], PigeonError> { | |||
let keyValueTuples = try! properties.map { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using try!
can cause a crash if the map
operation throws an error. The closure can throw an error, for example, for an unknown enum case or when sameSitePolicy
is used on an older OS version. Since the pigeonDefaultConstructor
function is marked with throws
, the error should be propagated with try
instead of try!
to prevent a potential crash.
let keyValueTuples = try! properties.map { | |
let keyValueTuples = try properties.map { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a Swift expert, @hellohuanlin what's the idiomatic thing to do here? And is that correct in the context of this plugin?
There are no warnings without the !
packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md
Outdated
Show resolved
Hide resolved
@@ -14,7 +14,7 @@ class HTTPCookieProxyAPIDelegate: PigeonApiDelegateHTTPCookie { | |||
) throws -> HTTPCookie { | |||
let registrar = pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar | |||
|
|||
let keyValueTuples = try! properties.map<[(HTTPCookiePropertyKey, Any)], PigeonError> { | |||
let keyValueTuples = try! properties.map { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was complaining because line 13 above in the function declaration already contains the type information [HttpCookiePropertyKey: Any]
Seen when upgrading to Xcode 26.
Introduced in #8311.
Fixes flutter/flutter#173744
Pre-Review Checklist
[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assist
bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3