Skip to content

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 !

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the caller:

do {
api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
try api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api, url: urlArg),
withIdentifier: pigeonIdentifierArg)
reply(wrapResult(nil))
} catch {
reply(wrapError(error))

It wraps pigeonDefaultConstructor call under a do/catch block, and if it throws, it replies error to the dart side.

So if you use try here, when it throws, it will be eventually propagated to dart side;
If you use try! here, when it throws, it will crash.

Given that this code is setup this way (throwable method + do/try/catch block), I'd say the expected usage is not to crash. So let's go with try.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@@ -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]

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting! The old rule is that yon can always explicitly provide types, and what's more, sometimes you must explicitly provide types for super long statements where swift compiler fails auto-infer the types).

@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'
2 participants