swiftlang / swift

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

[SR-8898] CodeCompletion: Forward references do not show up in top-level module scope #51404

Open AnthonyLatsis opened 5 years ago

AnthonyLatsis commented 5 years ago
Previous ID SR-8898
Radar rdar://problem/44942051
Original Reporter @AnthonyLatsis
Type Bug
Environment Xcode 12.0 beta (12A6159)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | CodeCompletion | |Labels | Bug | |Assignee | @rintaro | |Priority | Medium | md5: 3b8fc482fb0b9539e17cde7ce92f056a

is duplicated by:

Issue Description:

@benlangmuir:

The real problem here is that consumeDecl wants to use IsTopLevel to mean TopLevelCode - i.e. a script or main.swift file, where you cannot make forward references at all - but the caller is passing in TopLevelLibrary as well, where forward references are fine. So we actually have the same bug already in e.g. inheritance completion where we only suggest the names earlier in the file.

Test case for inheritance completion:

$ cat t.swift 
class C {}
class E: #^A^# {}
class D {}

$ xcrun swift-ide-test -code-completion -code-completion-token=A -source-filename=t.swift | grep CurrMo
found code completion token A at offset 20
Decl[Class]/CurrModule:             C[#C#]; name=C

This should also find D.

benlangmuir commented 5 years ago

@swift-ci create

ahoppen commented 1 year ago

Another similar case once https://github.com/apple/swift/pull/62362 is merged

// RUN: %sourcekitd-test -req=cursor -pos=4:9 %s -- %s

let formatter: DateFormatter = {
    let formatter = DateFormatter()
    return formatter
}()

struct DateFormatter {}