This repository was archived by the owner on Nov 10, 2026. It is now read-only.
Repository navigation
Resolve inferred associated types such as Identifiable.ID in member types - #303
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 explicittypealias ID = …. If the compiler inferred the associated type instead, e.g.Identifiable.IDfrom anidproperty, bridging failed:The workaround was to add
typealias ID = String(often under#if os(Android)) to every such type.Change
CodebaseInfo.Context.resolveTypealiasnow resolves a member typeT.Xthat has no declared typealias or nested type in two ways:fixupProtocolConformanceGenericsrecords conformances such asIdentifiable<String>on the type, including conformances declared in extensions. If one ofT's conformed protocols has an associated typeX, its mapped type is used.Identifiable.IDthrough 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: Identifiablein a module that only exports its bridged API,T.IDfalls back to the type ofT's instanceidproperty. That is the same property Swift infersIDfrom. This only applies to members namedID.If
Tdeclares its own nested type with that name, e.g.enum ID, that type still wins.Testing
BridgeToKotlinTests.testInferredAssociatedTypeMember:MessageData.IDandRoom.ID(conformance in an extension) bridge asStringandInt.BridgeToKotlinTests.testDeclaredNestedIDTypeMember: a type with its own nestedIDclass keeps bridging it asItem.ID.CodebaseInfoTests.testInferredAssociatedTypeAcrossModules: resolution across modules via a JSON-round-trippedModuleExport, both with the refining protocol visible and with it unknown.Each new test fails without its part of the change. Full
SkipSyntaxTestspasses (873 tests).I also tested this on a production Skip Fuse app (16 Skip modules) after removing its explicit
typealias IDworkarounds. Stock 1.9.16 fails on a cross-moduleT.IDwith the error above; with this branch the transpile and host build succeed, and the generated Kotlin takesStringwhere the Swift API tookT.ID.🤖 Generated with Claude Code