@@ -1162,7 +1162,7 @@ static CodeCompletionResult::ExpectedTypeRelation calculateTypeRelation(
1162
1162
static CodeCompletionResult::ExpectedTypeRelation
1163
1163
calculateTypeRelationForDecl (const Decl *D, Type ExpectedType,
1164
1164
bool IsImplicitlyCurriedInstanceMethod,
1165
- bool UseFuncResultType = true ) {
1165
+ bool UseFuncResultType) {
1166
1166
auto VD = dyn_cast<ValueDecl>(D);
1167
1167
auto DC = D->getDeclContext ();
1168
1168
if (!VD)
@@ -1197,9 +1197,9 @@ calculateTypeRelationForDecl(const Decl *D, Type ExpectedType,
1197
1197
}
1198
1198
1199
1199
static CodeCompletionResult::ExpectedTypeRelation
1200
- calculateMaxTypeRelationForDecl (
1201
- const Decl *D, const ExpectedTypeContext &typeContext,
1202
- bool IsImplicitlyCurriedInstanceMethod = false ) {
1200
+ calculateMaxTypeRelationForDecl (const Decl *D,
1201
+ const ExpectedTypeContext &typeContext,
1202
+ bool IsImplicitlyCurriedInstanceMethod ) {
1203
1203
if (typeContext.empty ())
1204
1204
return CodeCompletionResult::ExpectedTypeRelation::Unknown;
1205
1205
@@ -1218,7 +1218,8 @@ calculateMaxTypeRelationForDecl(
1218
1218
continue ;
1219
1219
1220
1220
Result = std::max (Result, calculateTypeRelationForDecl (
1221
- D, Type, IsImplicitlyCurriedInstanceMethod));
1221
+ D, Type, IsImplicitlyCurriedInstanceMethod,
1222
+ /* UseFuncResultTy*/ true ));
1222
1223
1223
1224
// Map invalid -> unrelated when in a single-expression body, since the
1224
1225
// input may be incomplete.
@@ -1334,9 +1335,12 @@ CodeCompletionResult *CodeCompletionResultBuilder::takeResult() {
1334
1335
}
1335
1336
1336
1337
auto typeRelation = ExpectedTypeRelation;
1338
+ // FIXME: we don't actually have enough info to compute
1339
+ // IsImplicitlyCurriedInstanceMethod here.
1337
1340
if (typeRelation == CodeCompletionResult::Unknown)
1338
1341
typeRelation =
1339
- calculateMaxTypeRelationForDecl (AssociatedDecl, declTypeContext);
1342
+ calculateMaxTypeRelationForDecl (AssociatedDecl, declTypeContext,
1343
+ /* IsImplicitlyCurriedMethod*/ false );
1340
1344
1341
1345
return new (*Sink.Allocator ) CodeCompletionResult (
1342
1346
SemanticContext, NumBytesToErase, CCS, AssociatedDecl, ModuleName,
@@ -2012,8 +2016,10 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2012
2016
IsStaticMetatype = value;
2013
2017
}
2014
2018
2015
- void setExpectedTypes (ArrayRef<Type> Types, bool isSingleExpressionBody) {
2019
+ void setExpectedTypes (ArrayRef<Type> Types, bool isSingleExpressionBody,
2020
+ bool preferNonVoid = false ) {
2016
2021
expectedTypeContext.isSingleExpressionBody = isSingleExpressionBody;
2022
+ expectedTypeContext.preferNonVoid = preferNonVoid;
2017
2023
expectedTypeContext.possibleTypes .clear ();
2018
2024
expectedTypeContext.possibleTypes .reserve (Types.size ());
2019
2025
for (auto T : Types)
@@ -2026,7 +2032,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2026
2032
}
2027
2033
2028
2034
CodeCompletionContext::TypeContextKind typeContextKind () const {
2029
- if (expectedTypeContext.empty ()) {
2035
+ if (expectedTypeContext.empty () && !expectedTypeContext. preferNonVoid ) {
2030
2036
return CodeCompletionContext::TypeContextKind::None;
2031
2037
} else if (expectedTypeContext.isSingleExpressionBody ) {
2032
2038
return CodeCompletionContext::TypeContextKind::SingleExpressionBody;
@@ -3044,6 +3050,12 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
3044
3050
3045
3051
if (isUnresolvedMemberIdealType (ResultType))
3046
3052
Builder.setSemanticContext (SemanticContextKind::ExpressionSpecific);
3053
+
3054
+ if (!IsImplicitlyCurriedInstanceMethod &&
3055
+ expectedTypeContext.requiresNonVoid () &&
3056
+ ResultType->isVoid ()) {
3057
+ Builder.setExpectedTypeRelation (CodeCompletionResult::Invalid);
3058
+ }
3047
3059
};
3048
3060
3049
3061
if (!AFT || IsImplicitlyCurriedInstanceMethod) {
@@ -5924,7 +5936,9 @@ void DotExprLookup::performLookup(ide::CodeCompletionContext &CompletionCtx,
5924
5936
for (auto &Solution: Solutions) {
5925
5937
Lookup.setIsStaticMetatype (Solution.BaseIsStaticMetaType );
5926
5938
Lookup.getPostfixKeywordCompletions (Solution.Ty , BaseExpr);
5927
- Lookup.setExpectedTypes (Solution.ExpectedTypes , Solution.isSingleExpressionClosure );
5939
+ Lookup.setExpectedTypes (Solution.ExpectedTypes ,
5940
+ Solution.IsSingleExpressionClosure ,
5941
+ Solution.ExpectsNonVoid );
5928
5942
if (isDynamicLookup (Solution.Ty ))
5929
5943
Lookup.setIsDynamicLookup ();
5930
5944
Lookup.getValueExprCompletions (Solution.Ty , Solution.ReferencedDecl );
0 commit comments