swiftlang / swiftlang/swift-java

Property in Protocol extension with a Self constraint can produce uncompilable bridge

Open
#534 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature:jextract
Dominant language
Swift
Stars
1.2k
Forks
123
Avg merge
1d 7h
Merged PRs (30d)
16

Description

Reproduction

Found while running #486 on Alamofire. I think the gist of the issue is the following:

public protocol DownloadResponseSerializerProtocol {
    associatedtype SerializedObject
}
public struct URLResponseSerializer: DownloadResponseSerializerProtocol {
    public typealias SerializedObject = String
}
extension DownloadResponseSerializerProtocol where Self == URLResponseSerializer {
    public var url: URLResponseSerializer { fatalError("...") }
}

this code as of 5764bc2a1b706056121109dc0ab14fd3d771cbc5 fails the Swift bridge compilation with:

error: property 'url' requires the types 'Self' and 'URLResponseSerializer' be equivalent
 16 | @_cdecl("swiftjava_MySwiftLibrary_DownloadResponseSerializerProtocol_url$get")
 17 | public func swiftjava_MySwiftLibrary_DownloadResponseSerializerProtocol_url$get(_ self: UnsafeRawPointer, _ _result: UnsafeMutableRawPointer) {
 18 |   _result.assumingMemoryBound(to: URLResponseSerializer.self).initialize(to: self.assumingMemoryBound(to: DownloadResponseSerializerProtocol.self).pointee.url)
    |                                                                                                                                                            `- error: property 'url' requires the types 'Self' and 'URLResponseSerializer' be equivalent

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 with the protocol and constrained extension in the reproduction, then inspect the Swift bridge generation that emits swiftjava_MySwiftLibrary_DownloadResponseSerializerProtocol_url$get. Confirm the generated bridge handles the Self == URLResponseSerializer constraint without producing the reported compiler error, and validate the original reproduction against commit 5764bc2a1b706056121109dc0ab14fd3d771cbc5.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, swift
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.