skiptools / skiptools/skip

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

Open
#315 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

transpilation
Dominant language
Swift
Stars
3.2k
Forks
106
Avg merge
6d 13h
Merged PRs (30d)
1

Description

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)
}

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 minimal Swift example in the issue and trace how extensions declared on a typealias are handled during transpilation. Compare the output for extension Location and extension Coordinate2D; done means the typealias form transpiles and stringValue resolves when called on Location.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.