Skip to content
This repository was archived by the owner on Nov 10, 2026. It is now read-only.

Emit Kotlin collection literals for kotlincompat bridged default values - #297

Merged
marcprux merged 1 commit into
mainfrom
fix/kotlincompat-collection-defaults
Oct 11, 2026
Merged

marcprux merged 1 commit into
mainfrom
fix/kotlincompat-collection-defaults

Conversation

@piercifani

Copy link
Copy Markdown
Contributor

Problem

With bridging.options: kotlincompat, a bridged parameter of type [T], Set<T> or [K: V] is declared in Kotlin as kotlin.collections.List/Set/Map, but a literal default value was still emitted as Skip's arrayOf() / setOf() / dictionaryOf():

public func f(names: [String] = ["a", "b"]) { }
// before: does not compile, arrayOf() builds a skip.lib.Array
fun f(names: kotlin.collections.List<String> = arrayOf("a", "b")): Unit = Swift_f_0(names)
// after
fun f(names: kotlin.collections.List<String> = kotlin.collections.listOf("a", "b")): Unit = Swift_f_0(names)

So bridged APIs either drop collection defaults, take [T]? = nil and fall back with ?? [...] in the body, or mark the declaration @nobridge.

Fix

When the bridge rewrites parameter types for kotlincompat, mark array and dictionary literal defaults so they emit fully qualified kotlin.collections.listOf / setOf / mapOf(Pair(k, v)). Nested literals ([[Int]], [String: [Int]]) are converted too. Elements are untouched, so [.mock1(), .mock2()] becomes kotlin.collections.listOf(T.mock1(), T.mock2()).

Non-literal defaults (e.g. = Self.defaultValues) are not converted.

Tests

Added testCollectionDefaultValueKotlinCompatibilityOption to BridgeToKotlinTests. SkipSyntaxTests pass.

🤖 Generated with Claude Code

With the kotlincompat bridging option, bridged parameters of array, set and
dictionary type are declared as kotlin.collections.List/Set/Map, but literal
default values were still emitted as Skip's arrayOf()/setOf()/dictionaryOf(),
which do not type-check against those parameter types. Emit
kotlin.collections.listOf/setOf/mapOf instead, including nested literals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cla-bot cla-bot Bot added the cla-signed label Oct 9, 2026
@marcprux
marcprux merged commit 9417e71 into main Oct 11, 2026
15 of 17 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants