Is this a `typealias` issue?


(Adrian Zubarev) #1

Consider the following code:

public typealias Something = Int
public func something() -> Something {
  return 42
}

public typealias Test<T> = T
public func test() -> Test<Int> {
  return 42
}

When viewing the imported module interface the result will become:

public typealias Something = Int
public func something() -> Something

public typealias Test<T> = T
public func test() -> Int 

However I did expect public func test() -> Test<Int>, because the typealias is just a visual marker in that case.


(Jordan Rose) #2

At one point we didn't have the information necessary to properly preserve generic typealiases post-type-checking, but I think we do now. @Slava_Pestov?


(Adrian Zubarev) #3

I cannot test it on my current machine, but on the other one with Xcode 10 beta 6 it was still the same. So I guess this has not landed in the Swift 4.2 branch, if it was already fixed?

If the issue is unknown then I can file a bug.


(Slava Pestov) #4

I tested on Xcode 10 beta 6 and I see the following output:

public typealias Something = Int
public func something() -> Something
public typealias Test<T> = T
public func test() -> Test<Int>

The steps I followed:

  • Create a new Cocoa project
  • Paste your code in AppDelegate.swift
  • Switch to the generated interface view

I also checked and @Douglas_Gregor's changes landed in the swift-4.2-branch -- https://github.com/apple/swift/commit/e82e7ee908ed5ceb3c3dcd36a36563aa4b307a23

It is possible that something else is going wrong here. Can you share more details about what you're doing?


(Jordan Rose) #5

Ah, the generated interface view doesn't go through serialization.

I didn't necessarily mean that we'd fixed the issue yet, just that we had the pieces in place to do so. I don't think we actually changed Serialization to not look through bound generic typealiases.


(Slava Pestov) #6

I took a quick look at Serialization.cpp and we do serialize NameAliasType.


(Slava Pestov) #7

Turns out the problem was in deserialization. I have a fix: https://github.com/apple/swift/pull/19253


(Adrian Zubarev) #8

Here are the steps where I can always reproduce it in Xcode 10 beta 6 (it uses the default toolchain):

  • create a playground project
  • add a new swift file to Sources
  • add this short code
    public typealias Test<T> = T
    public func test() -> Test<Int> {
      return 42
    }
    
  • go back to the main playground page
  • type <playground name>_Sources
  • cmd + left click on that identifier
  • click on Jump to Definition
  • the result will be:
    public typealias Test<T> = T
    public func test() -> Int
    

Thank you for the quick help and the blazing fast PR. Hopefully it will make into Swift 4.2.x if not in 4.2 which is probably too late.


(Slava Pestov) #9

The fix is not going into swift-4.2-branch, sorry. It changes the serialization format and that in itself introduces a bit of risk.