Skip to content

[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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jmagman
Copy link
Member

@jmagman jmagman commented Aug 14, 2025

Seen when upgrading to Xcode 26.

Introduced in #8311.

Fixes flutter/flutter#173744

Pre-Review Checklist

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

  1. 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

Copy link

@gemini-code-assist gemini-code-assist bot left a 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 {

Choose a reason for hiding this comment

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

high

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.

Suggested change
let keyValueTuples = try! properties.map {
let keyValueTuples = try properties.map {

Copy link
Member Author

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 !

@@ -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 {
Copy link
Member Author

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]

@jmagman jmagman changed the title [webview_flutter_wkwebview] Remove specialization of 'map' in example app to fix Swift warning [webview_flutter_wkwebview] Remove specialization of 'map' to fix Swift warning Aug 14, 2025
@jmagman jmagman marked this pull request as ready for review August 14, 2025 18:09
@jmagman jmagman requested a review from LouiseHsu as a code owner August 14, 2025 18:09
@jmagman jmagman requested a review from hellohuanlin August 14, 2025 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[webview_flutter_wkwebview] HTTPCookieProxyAPIDelegate warning Cannot explicitly specialize instance method 'map'
1 participant