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

Resolve inferred associated types such as Identifiable.ID in member types - #303

Merged
piercifani merged 1 commit into
mainfrom
fix/inferred-associated-typealias
Oct 22, 2026
Merged

piercifani merged 1 commit into
mainfrom
fix/inferred-associated-typealias

Conversation

@piercifani

@piercifani piercifani commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes skiptools/skip-bridge#49

Why

A bridged API that names an associated type through a member type, such as MessageData.ID, only resolved when the type declared an explicit typealias ID = …. If the compiler inferred the associated type instead, e.g. Identifiable.ID from an id property, bridging failed:

error: 'MessageData.ID' does not appear to be a bridged type

The workaround was to add typealias ID = String (often under #if os(Android)) to every such type.

Change

CodebaseInfo.Context.resolveTypealias now resolves a member type T.X that has no declared typealias or nested type in two ways:

  1. From the conformance mappings skipstone already infers. fixupProtocolConformanceGenerics records conformances such as Identifiable<String> on the type, including conformances declared in extensions. If one of T's conformed protocols has an associated type X, its mapped type is used.
  2. Identifiable.ID through a protocol skipstone can't see. If the conformance comes through a refining protocol that isn't in the codebase info, e.g. protocol Entity: Identifiable in a module that only exports its bridged API, T.ID falls back to the type of T's instance id property. That is the same property Swift infers ID from. This only applies to members named ID.

If T declares its own nested type with that name, e.g. enum ID, that type still wins.

Testing

  • BridgeToKotlinTests.testInferredAssociatedTypeMember: MessageData.ID and Room.ID (conformance in an extension) bridge as String and Int.
  • BridgeToKotlinTests.testDeclaredNestedIDTypeMember: a type with its own nested ID class keeps bridging it as Item.ID.
  • CodebaseInfoTests.testInferredAssociatedTypeAcrossModules: resolution across modules via a JSON-round-tripped ModuleExport, both with the refining protocol visible and with it unknown.

Each new test fails without its part of the change. Full SkipSyntaxTests passes (873 tests).

I also tested this on a production Skip Fuse app (16 Skip modules) after removing its explicit typealias ID workarounds. Stock 1.9.16 fails on a cross-module T.ID with the error above; with this branch the transpile and host build succeed, and the generated Kotlin takes String where the Swift API took T.ID.

🤖 Generated with Claude Code

…ypes

A member type like `T.ID` only resolved when `T` declared an explicit
`typealias ID`. When the compiler infers the associated type instead, e.g.
`Identifiable.ID` from an `id` property, bridging failed with
"'T.ID' does not appear to be a bridged type".

Resolve such member types from the generic mappings already recorded on the
type's protocol conformances, and fall back to the `id` property's type for
`ID` when the Identifiable conformance comes through a protocol we have no
info for (e.g. one in a module that only exports its bridged API). A declared
nested type of the same name still takes precedence.

Fixes skiptools/skip-bridge#49

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cla-bot cla-bot Bot added the cla-signed label Oct 20, 2026

@marcprux marcprux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great improvement!

@piercifani
piercifani merged commit 342d013 into main Oct 22, 2026
9 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.

ID not automatically created for Identifiable types

2 participants