skip icon indicating copy to clipboard operation
skip copied to clipboard

Bug: Variables or functions declared in a typealiased extension are not transpiled

Open lexum0 opened this issue 11 months ago • 0 comments

I found an issue in the transpiled code. Declaring a variable or function in an extension for a typealias type will give the error Unresolved reference 'stringValue' when calling it.

If the extension is declared for the original type (Coordinate2D in this case) both types get the extension's variables or functions. If the extension is declared for the typealias (Location) it seems like the code is not transpiled at all.

Testing it in Swift seems like the extension is declared using the original type Coordinate2D instead of the Location typealias, so I think maybe the transpiler should convert the typealias to the assigned type in the extension declaration

Here's a simple example, just swap lines 1. and 2. to see the error:

struct Coordinate2D {
    var lat: Double
    var lon: Double 
}
typealias Location = Coordinate2D

extension Location { // <- 1. Error: Unresolved reference 'stringValue'
//extension Coordinate2D { // <- 2. This one works
    var stringValue: String { "\(lat),\(lon)" }
}
func test() {
    print(Location(lat: 1, lon: 2).stringValue)
}

lexum0 avatar Jan 10 '25 21:01 lexum0