Skip to content

[pigeon] Swift generator cast for Object arguments generates warning #117994

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

Closed
stuartmorgan-g opened this issue Jan 4, 2023 · 1 comment · Fixed by flutter/packages#3020
Closed
Assignees
Labels
p: pigeon related to pigeon messaging codegen tool P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-ios iOS applications specifically platform-mac Building on or for macOS specifically

Comments

@stuartmorgan-g
Copy link
Contributor

Making a Pigeon HostApi definition including:

  void setValue(String key, Object value);

generates code including:

  let valueArg = args[1] as! Any

This creates the following warning at compile time:

.../messages.g.swift:73:32: warning: forced cast from 'Any?' to 'Any' only unwraps optionals; did you mean to use '!'?
        let valueArg = args[1] as! Any

We should special-case Object so that it generates let valueArg = args[1]! instead.

@stuartmorgan-g stuartmorgan-g added platform-ios iOS applications specifically platform-mac Building on or for macOS specifically package flutter/packages repository. See also p: labels. p: pigeon related to pigeon messaging codegen tool P2 Important issues not at the top of the work list labels Jan 4, 2023
@stuartmorgan-g stuartmorgan-g self-assigned this Jan 5, 2023
stuartmorgan-g added a commit to flutter/packages that referenced this issue Jan 5, 2023
Fixes a warning in generated Swift output when an argument is of type Object. This is blocking flutter/plugins#6914 since we check our macOS and iOS plugin code for warnings in CI.

Rather than add a Dart generator unit test for this one specific case, I tightened the Swift compilation settings for our test plugin to treat warnings as errors (per flutter/flutter#59116 (comment)) to catch the entire class of errors, and added echo* variants for Object to make sure this one then showed up.

Incidental fixes:

I had to make a similar fix to the Dart generator for a similar warning with casting to Object?, which we'd never noticed because we weren't analyzing any generated code that returning Object or Object? before.
I had to make a change to the C++ generator so that generation would succeed, because it turned out we had no handling at all of Object in the C++ generator, causing it to throw. I'm not sure this is the output I'll keep for C++ (thus the TODO), but it's the simple fix to make it work at all.
Fixes flutter/flutter#117994
Part of flutter/flutter#59116
@github-actions
Copy link

github-actions bot commented Mar 4, 2023

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 flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p: pigeon related to pigeon messaging codegen tool P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-ios iOS applications specifically platform-mac Building on or for macOS specifically
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant