@@ -3576,12 +3576,35 @@ void LocatableType::Profile(llvm::FoldingSetNodeID &id, SourceLoc loc,
35763576// Simple accessors.
35773577Type ErrorType::get (const ASTContext &C) { return C.TheErrorType ; }
35783578
3579+ static Type replacingTypeVariablesAndPlaceholders (Type ty) {
3580+ if (!ty || !ty->hasTypeVariableOrPlaceholder ())
3581+ return ty;
3582+
3583+ auto &ctx = ty->getASTContext ();
3584+
3585+ return ty.transformRec ([&](Type ty) -> std::optional<Type> {
3586+ if (!ty->hasTypeVariableOrPlaceholder ())
3587+ return ty;
3588+
3589+ // Match the logic in `Solution::simplifyType` and use UnresolvedType.
3590+ // FIXME: Ideally we'd get rid of UnresolvedType and just use a fresh
3591+ // PlaceholderType, but we don't currently support placeholders with no
3592+ // originators.
3593+ auto *typePtr = ty.getPointer ();
3594+ if (isa<TypeVariableType>(typePtr) || isa<PlaceholderType>(typePtr))
3595+ return ctx.TheUnresolvedType ;
3596+
3597+ return std::nullopt ;
3598+ });
3599+ }
3600+
35793601Type ErrorType::get (Type originalType) {
3602+ // The original type is only used for printing/debugging, and we don't support
3603+ // solver-allocated ErrorTypes. As such, fold any type variables and
3604+ // placeholders into UnresolvedTypes, which print as placeholders.
3605+ originalType = replacingTypeVariablesAndPlaceholders (originalType);
3606+
35803607 ASSERT (originalType);
3581- // We don't currently support solver-allocated error types, if we want
3582- // this in the future we'll need to adjust `Solution::simplifyType` to fold
3583- // them into regular ErrorTypes. Additionally, any clients of
3584- // `typesSatisfyConstraint` will need to be taught not to pass such types.
35853608 ASSERT (!originalType->getRecursiveProperties ().isSolverAllocated () &&
35863609 " Solver-allocated error types not supported" );
35873610
0 commit comments