Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-8801] SourceKit and -dump-ast report incorrect types for functions returning typealiases #51309

Open
swift-ci opened this issue Sep 19, 2018 · 2 comments
Labels
access control Feature → modifiers: Access control and access levels bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.2

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-8801
Radar None
Original Reporter fourdman (JIRA User)
Type Bug

Attachment: Download

Environment

Apple Swift version 4.2 (swiftlang-1000.11.37.1 clang-1000.11.45.1)
Target: x86_64-apple-darwin17.7.0

macos High Sierra, 10.13.6 (17G65)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.2Regression
Assignee None
Priority Medium

md5: 110365d091ca8a63642e8cbbf698f0de

Issue Description:

In some situations, SourceKit cursor info/cmd+click in Xcode and `swiftc -dump-ast` report incorrect return type for functions that return typealises. In particular, the expanded type is reported instead of the typealias itself.

The expected behavior is that both would report function return type keeping the typealias as-is.

Notably, SourceKit and `swiftc -dump-ast` differ in behavior depending on where the typealias and the function is defined.

For more details, see the example below:

typealias TA = () -> Int

public protocol P {
  typealias TA = () -> Int
}

func makeTA() -> TA {
  return { return 42 }
}

func makeP_TA() -> P.TA {
  return { return 42 }
}

class C {
  static func makeTA() -> TA {
    return { return 42 }
  }

  static func makeP_TA() -> P.TA {
    return { return 42 }
  }
}

func use<T>(_ t: T) {
}

// -dump-ast for makeTA: (declref_expr type='() -> TA' ...
// Cursor info in Xcode: func makeTA() -> TA
use(makeTA)

// -dump-ast for makeP_TA: (declref_expr type='() -> () -> Int' ...
// Cursor info in Xcode: func makeP_TA() -> P.TA
use(makeP_TA)

// -dump-ast for C.makeTA: (declref_expr type='(C.Type) -> () -> TA' ...
// Cursor info in Xcode: static func makeTA() -> TA
use(C.makeTA)

// -dump-ast for C.makeP_TA: (declref_expr type='(C.Type) -> () -> () -> Int' ...
// Cursor info in Xcode: static func makeP_TA() -> () -> Int
use(C.makeP_TA)

This behavior changed from Xcode 9.4.1 and 10. Swift 4.1.2 in the former reports all return types as the typealias, as expected.

@belkadan
Copy link
Contributor

Hm. @slavapestov, is this a consequence of protocols being generic contexts?

@slavapestov
Copy link
Member

It's because Type::subst() doesn't always preserve typealias sugar. By coincidence I was looking at this yesterday and it's a bit tricky to fix.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added regression swift 4.2 access control Feature → modifiers: Access control and access levels and removed 4.2 regression labels Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
access control Feature → modifiers: Access control and access levels bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.2
Projects
None yet
Development

No branches or pull requests

4 participants