Skip to content
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

Ensure that conversions are defined for lambdas defined in struct #1605

Merged

Conversation

pwrobeldev
Copy link
Contributor

In the case of Swift language, when lambda was defined in a structure, then the code could not compile because of missing conversion functions. Interestingly, that was not the case for classes.

After investigation it turned out, that the root cause is related to missing inclusion of SwiftLambdaConversion template in SwiftStructConversion.

This change:

  • adds missing inclusion of lambda conversions in the mentioned template (SwiftStructConversion.mustache)
  • implements functional tests for Swift to check that the fix works as expected
  • implements functional tests for Dart and Android to also cover the tested case in these technologies
  • updates the reference files for smoke tests related to definition of nested fields in structs

@pwrobeldev
Copy link
Contributor Author

A few notes for reviewers can be found below.

  1. SwiftLambdaDefinition.mustache is used in three files: SwiftClassDefinition.mustache, SwiftInterfaceDefinition..mustache and SwiftStructDefinition.mustache.
  2. In the case of SwiftClassDefinition.mustache and SwiftInterfaceDefinition.mustache the conversion functions for lambda are included via SwiftClassConversion.mustache. This particular template is used also for interfaces. Its selection is present in SwiftGenerator.kt --> private fun selectConversionTemplate().
  3. In the case of SwiftStructDefinition.mustache it should be included by SwiftStructConversion.mustache. This change adjusts the latter file to include SwiftLambdaConversion.mustache.

struct StructWithLambda {
lambda LambdaCallback = (String?) -> String?

static fun invoke_callback(callback: LambdaCallback?): String?
Copy link
Contributor

Choose a reason for hiding this comment

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

Was it necessary to make lambda (and its parameters) optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not check it before pushing the change. I used the received reproducer.

It has just been checked and it seems, that even without any optional parameters the problem reproduces.

E.g.:

lambda InnerLambda = () -> Void

static fun invoke_callback(callback: InnerLambda)

@pwrobeldev pwrobeldev force-pushed the pwrobeldev/missing-lambda-conversion-functions-in-swift branch 2 times, most recently from d4f4b31 to 90c5060 Compare October 23, 2024 12:04
Hsilgos
Hsilgos previously approved these changes Oct 23, 2024
In the case of Swift language, when lambda was defined in
a structure, then the code could not compile because of
missing conversion functions. Interestingly, that was not
the case for classes.

After investigation it turned out, that the root cause is
related to missing inclusion of SwiftLambdaConversion
template in SwiftStructConversion.

This change:
 - adds missing inclusion of lambda conversions in the
   mentioned template (SwiftStructConversion.mustache)
 - implements functional tests for Swift to check that
   the fix works as expected
 - implements functional tests for Dart and Android to
   also cover the tested case in these technologies
 - updates the reference files for smoke tests related
   to definition of nested fields in structs

Signed-off-by: Patryk Wrobel <[email protected]>
@pwrobeldev pwrobeldev force-pushed the pwrobeldev/missing-lambda-conversion-functions-in-swift branch from 90c5060 to a615096 Compare October 24, 2024 07:12
@pwrobeldev
Copy link
Contributor Author

No functional changes since last patch-set -- only Changelog.md was updated.

@pwrobeldev pwrobeldev merged commit 7099f8f into master Oct 24, 2024
17 checks passed
@pwrobeldev pwrobeldev deleted the pwrobeldev/missing-lambda-conversion-functions-in-swift branch October 24, 2024 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants