margelo / margelo/nitro

Tuple (`[A, B, C]`) doesn't work in Swift

Open
#38 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement swift
Dominant language
C++
Stars
1.9k
Forks
117
Avg merge
1d 8h
Merged PRs (30d)
44

Description

When creating a tuple, the Swift code gets generated but it won't compile.

Tuple:

interface MyHybrid extends HybridObject<{ ios: 'swift' }> {
  someFunc(value: [number, number, number])
}

Generated Swift:

class MyHybrid implements MyHybridSpec {
  func someFunc(value: (Double, Double, Double)) {
    // do nothing
  }
}

Looks good, but unfortunately it will fail to compile because the Swift compiler inserted an additional < and > around the C++ type (std::tuple<<...>> instead of std::tuple<..>) in the generated -Swift.h header:

- SWIFT_INLINE_THUNK std::__1::tuple<<double, double, std::string>> MyHybridSpecCxx::getSomeTuple() {

I already reported this bug in the Swift compiler repo: https://github.com/swiftlang/swift/issues/75865

Until that's fixed, tuples are currently not supported in Nitrogen.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the tuple case from the issue and inspecting the generated -Swift.h declaration. Read the linked Swift compiler issue #75865 to determine whether a project-side path remains available. Done means tuple support no longer produces the malformed nested std::tuple angle brackets and the generated Swift interface compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, swift, typescript
Domain
compilers, mobile-dev
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.