Skip to content

Apply spread operator for transpiled static functions #64

@marcprux

Description

@marcprux

When a static function has a varargs parameter, the companion function needs to use the spread ("*") operator to correctly pass the parameter through to its companion object implementation.

E.g., the following Swift:

public class AndroidBridge {
    public static func initBridge(context: android.content.Context, _ libraryNames: String...) throws {
    }

transpiles to the Kotlin:

open class AndroidBridge {
    companion object: CompanionClass() {
        override fun initBridge(context: android.content.Context, vararg libraryNames: String) {
    }
    open class CompanionClass {
        open fun initBridge(context: android.content.Context, vararg libraryNames: String) = AndroidBridge.initBridge(context = context, libraryNames)
    }
}

This results in the compile error:

Argument type mismatch: actual type is 'kotlin.Array<CapturedType(out kotlin.String)>', but 'kotlin.String' was expected.

I think we just need to add the spread operator to the parameter, i.e.:

        open fun initBridge(context: android.content.Context, vararg libraryNames: String) = AndroidBridge.initBridge(context = context, *libraryNames)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions