swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.57k stars 10.35k forks source link

[SR-14842] Code completion reporting wrong base of type alias on generic function #57189

Open ahoppen opened 3 years ago

ahoppen commented 3 years ago
Previous ID SR-14842
Radar rdar://79862826
Original Reporter @ahoppen
Type Bug
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | CodeCompletion | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 13bbc4a62166141d507c9a58a580f9ae

Issue Description:

Consider this test case.

// RUN: %swift-ide-test --code-completion --source-filename %s --code-completion-token=COMPLETE

public class Foo {
  typealias Value = Int
}

public class Foo2: Foo {
  typealias Value = String
}

public class Bar<T: Foo> {
  func foo() -> T.Value {
    fatalError()
  }
}

func f(x: Bar<Foo2>) {
  x.#^COMPLETE^#
}

It reports

Begin completions, 2 items
Keyword[self]/CurrNominal:          self[#Bar<Foo2>#]; name=self
Decl[InstanceMethod]/CurrNominal/TypeRelation[Identical]: foo()[#Foo.Value#]; name=foo()
End completions

But since x is of type Bar<Foo2> (not Bar<Foo>), the return type of foo should be Foo2.Value, not Foo.Value.

typesanitizer commented 3 years ago

@swift-ci create