From a976af09badb687f2f3b8fc04deac742cc87b8bb Mon Sep 17 00:00:00 2001 From: Hamish Knight Date: Wed, 17 Sep 2025 22:44:21 +0100 Subject: [PATCH] [IDE] Ignore unresolved types in WithSolutionSpecificVarTypesRAII Make sure we don't try to set an UnresolvedType as a VarDecl interface type in WithSolutionSpecificVarTypesRAII. --- include/swift/IDE/TypeCheckCompletionCallback.h | 17 +++++++---------- .../IDE/crashers_fixed/bfc920b5867dcc4c.swift | 7 +++++++ .../c9b7522368139eb7.swift | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 validation-test/IDE/crashers_fixed/bfc920b5867dcc4c.swift rename validation-test/IDE/{crashers => crashers_fixed}/c9b7522368139eb7.swift (66%) diff --git a/include/swift/IDE/TypeCheckCompletionCallback.h b/include/swift/IDE/TypeCheckCompletionCallback.h index 2d00e8453454a..371c29fe907ba 100644 --- a/include/swift/IDE/TypeCheckCompletionCallback.h +++ b/include/swift/IDE/TypeCheckCompletionCallback.h @@ -86,19 +86,16 @@ struct WithSolutionSpecificVarTypesRAII { WithSolutionSpecificVarTypesRAII( llvm::SmallDenseMap SolutionSpecificVarTypes) { - for (auto SolutionVarType : SolutionSpecificVarTypes) { - if (SolutionVarType.first->hasInterfaceType()) { - RestoreVarTypes[SolutionVarType.first] = - SolutionVarType.first->getInterfaceType(); + for (auto &[var, ty] : SolutionSpecificVarTypes) { + if (var->hasInterfaceType()) { + RestoreVarTypes[var] = var->getInterfaceType(); } else { - RestoreVarTypes[SolutionVarType.first] = Type(); + RestoreVarTypes[var] = Type(); } - if (!SolutionVarType.second->hasArchetype()) { - setInterfaceType(const_cast(SolutionVarType.first), - SolutionVarType.second); + if (!ty->hasArchetype() && !ty->hasUnresolvedType()) { + setInterfaceType(const_cast(var), ty); } else { - setInterfaceType(const_cast(SolutionVarType.first), - ErrorType::get(SolutionVarType.second)); + setInterfaceType(const_cast(var), ErrorType::get(ty)); } } } diff --git a/validation-test/IDE/crashers_fixed/bfc920b5867dcc4c.swift b/validation-test/IDE/crashers_fixed/bfc920b5867dcc4c.swift new file mode 100644 index 0000000000000..b2dc41c9cf1b2 --- /dev/null +++ b/validation-test/IDE/crashers_fixed/bfc920b5867dcc4c.swift @@ -0,0 +1,7 @@ +// {"kind":"complete","original":"03137cdb","signature":"swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::constraints::SyntacticElementTarget)","signatureAssert":"Assertion failed: (isValidType(type) && \"type binding has invalid type\"), function applySolution"} +// RUN: %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s +@propertyWrapper struct ais() && \"Interface type must be materializable\"), function cacheResult"} -// RUN: not --crash %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s +// RUN: %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s [ #^^# ].reduce?(