diff --git a/lib/IDE/ExprCompletion.cpp b/lib/IDE/ExprCompletion.cpp index f7eb47c15d3e1..334363f1dbff9 100644 --- a/lib/IDE/ExprCompletion.cpp +++ b/lib/IDE/ExprCompletion.cpp @@ -119,6 +119,12 @@ void ExprTypeCheckCompletionCallback::collectResults( UnifiedCanHandleAsync |= Result.IsInAsyncContext; } + // If we didn't find any results, at least try to collect unqualified results. + if (Results.empty()) { + Lookup.getValueCompletionsInDeclContext(CCLoc); + Lookup.getSelfTypeCompletionInDeclContext(CCLoc, /*isForDeclResult=*/false); + } + collectCompletionResults(CompletionCtx, Lookup, DC, UnifiedTypeContext, UnifiedCanHandleAsync); } diff --git a/test/IDE/complete_unqualified_fallback.swift b/test/IDE/complete_unqualified_fallback.swift new file mode 100644 index 0000000000000..826652eb38126 --- /dev/null +++ b/test/IDE/complete_unqualified_fallback.swift @@ -0,0 +1,56 @@ +// RUN: %batch-code-completion + +protocol P0 {} +protocol P1 {} +protocol P2 {} +protocol P3 {} +protocol P4 {} +protocol P5 {} +protocol P6 {} +protocol P7 {} +protocol P8 {} +protocol P9 {} + +struct FooBar: P0 {} + +@resultBuilder +struct Builder { + static func buildBlock(_ x: T) -> T { x } + static func buildExpression(_ x: T) -> T { x } + static func buildExpression(_ x: T) -> T { x } + static func buildExpression(_ x: T) -> T { x } + static func buildExpression(_ x: T) -> T { x } + static func buildExpression(_ x: T) -> T { x } + static func buildExpression(_ x: T) -> T { x } + static func buildExpression(_ x: T) -> T { x } + static func buildExpression(_ x: T) -> T { x } + static func buildExpression(_ x: T) -> T { x } + static func buildExpression(_ x: T) -> T { x } +} + +struct S {} +extension S: P0 where T : P0 { init(@Builder fn: () -> T) {} } +extension S: P1 where T : P1 { init(@Builder fn: () -> T) {} } +extension S: P2 where T : P2 { init(@Builder fn: () -> T) {} } +extension S: P3 where T : P3 { init(@Builder fn: () -> T) {} } +extension S: P4 where T : P4 { init(@Builder fn: () -> T) {} } +extension S: P5 where T : P5 { init(@Builder fn: () -> T) {} } +extension S: P6 where T : P6 { init(@Builder fn: () -> T) {} } +extension S: P7 where T : P7 { init(@Builder fn: () -> T) {} } +extension S: P8 where T : P8 { init(@Builder fn: () -> T) {} } +extension S: P9 where T : P9 { init(@Builder fn: () -> T) {} } + +// This is currently too complex, make sure we can still do an unqualified +// lookup though. +S { + S { + S { + S { + S { + #^COMPLETE^# + // COMPLETE: Decl[Struct]/CurrModule: FooBar[#FooBar#]; name=FooBar + } + } + } + } +}