skiptools / skiptools/skip-lib

withThrowingTaskGroup(of:returning:isolation:body:) transpiled incorrectly

Open
#24 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Swift
Stars
13
Forks
4
Avg merge
1h 49m
Merged PRs (30d)
2

Description

Issue

I have a function with the following Swift code:

var allProducts: [FNCProduct] = []

try await withThrowingTaskGroup(of: [FNCProduct].self) { pageProductsTaskGroup in
    // Some irrelevant code

    for try await pageProducts in pageProductsTaskGroup {
        allProducts.append(contentsOf: pageProducts)
    }
}

return allProducts

This gets transpiled to the following Kotlin code:

var allProducts: Array<FNCProduct> = arrayOf()

withThrowingTaskGroup(of = Array::class) { pageProductsTaskGroup ->
    // Some irrelevant code

    for (pageProducts in pageProductsTaskGroup.sref()) {
        allProducts.append(contentsOf = pageProducts)
    }
}

return@l allProducts.sref()

I'm getting an error from the compiler that refers to the following line:
allProducts.append(contentsOf = pageProducts)

Argument type mismatch: actual type is 'skip.lib.Array<CapturedType(*)>', but 'skip.lib.Sequence<funico.module.FNCProduct>' was expected.

Issue
Proposed solution:

I think this:

withThrowingTaskGroup(of = Array::class)

needs to change to this:

withThrowingTaskGroup(of = Array<FNCProduct>::class)

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 issue with the Swift withThrowingTaskGroup(of:returning:isolation:body:) example and inspect the generated Kotlin call using Array::class. The fix is complete when the generated type preserves FNCProduct and the append(contentsOf:) line compiles without the reported type mismatch.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, swift
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.