@@ -3576,12 +3576,35 @@ void LocatableType::Profile(llvm::FoldingSetNodeID &id, SourceLoc loc,
3576
3576
// Simple accessors.
3577
3577
Type ErrorType::get (const ASTContext &C) { return C.TheErrorType ; }
3578
3578
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
+
3579
3601
Type 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
+
3580
3607
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.
3585
3608
ASSERT (!originalType->getRecursiveProperties ().isSolverAllocated () &&
3586
3609
" Solver-allocated error types not supported" );
3587
3610
0 commit comments