diff --git a/include/swift/AST/Types.h b/include/swift/AST/Types.h index a320e4885957a..c57835c040bc8 100644 --- a/include/swift/AST/Types.h +++ b/include/swift/AST/Types.h @@ -7291,7 +7291,7 @@ class PlaceholderType : public TypeBase { // recursive property logic in PlaceholderType::get. using Originator = llvm::PointerUnion; + ErrorExpr *, TypeRepr *>; Originator O; diff --git a/include/swift/Sema/ConstraintLocator.h b/include/swift/Sema/ConstraintLocator.h index 198a87887947a..631e84cdcc24d 100644 --- a/include/swift/Sema/ConstraintLocator.h +++ b/include/swift/Sema/ConstraintLocator.h @@ -985,13 +985,13 @@ class LocatorPathElt::ConformanceRequirement final }; class LocatorPathElt::PlaceholderType final - : public StoredPointerElement { + : public StoredPointerElement { public: - PlaceholderType(PlaceholderTypeRepr *placeholderRepr) + PlaceholderType(TypeRepr *placeholderRepr) : StoredPointerElement(PathElementKind::PlaceholderType, placeholderRepr) {} - PlaceholderTypeRepr *getPlaceholderRepr() const { return getStoredPointer(); } + TypeRepr *getPlaceholderRepr() const { return getStoredPointer(); } static bool classof(const LocatorPathElt *elt) { return elt->getKind() == ConstraintLocator::PlaceholderType; diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index 1b80e0166f84d..d774b751168cc 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -3989,8 +3989,8 @@ namespace { printFlag("error_expr"); } else if (auto *DMT = originator.dyn_cast()) { printRec(DMT, "dependent_member_type"); - } else if (originator.is()) { - printFlag("placeholder_type_repr"); + } else if (originator.is()) { + printFlag("type_repr"); } else { assert(false && "unknown originator"); } diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp index 7386a96a94cde..06f92d07f72e1 100644 --- a/lib/AST/ASTPrinter.cpp +++ b/lib/AST/ASTPrinter.cpp @@ -6021,8 +6021,8 @@ class TypePrinter : public TypeVisitor { Printer << "error_expr"; } else if (auto *DMT = originator.dyn_cast()) { visit(DMT); - } else if (originator.is()) { - Printer << "placeholder_type_repr"; + } else if (originator.is()) { + Printer << "type_repr"; } else { assert(false && "unknown originator"); } diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index e0a9dbadcf6e0..708646ada1c31 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -9338,7 +9338,7 @@ bool InvalidMemberReferenceWithinInitAccessor::diagnoseAsError() { } bool ConcreteTypeSpecialization::diagnoseAsError() { - emitDiagnostic(diag::not_a_generic_type, resolveType(ConcreteType)); + emitDiagnostic(diag::not_a_generic_type, ConcreteType); return true; } diff --git a/lib/Sema/CSDiagnostics.h b/lib/Sema/CSDiagnostics.h index 95bfef7de4a04..f95b626e69110 100644 --- a/lib/Sema/CSDiagnostics.h +++ b/lib/Sema/CSDiagnostics.h @@ -3116,7 +3116,7 @@ class ConcreteTypeSpecialization final : public FailureDiagnostic { ConcreteTypeSpecialization(const Solution &solution, Type concreteTy, ConstraintLocator *locator) : FailureDiagnostic(solution, locator), - ConcreteType(concreteTy) {} + ConcreteType(resolveType(concreteTy)) {} bool diagnoseAsError() override; }; diff --git a/lib/Sema/CSGen.cpp b/lib/Sema/CSGen.cpp index 305debe7bfbe0..922a738c443a7 100644 --- a/lib/Sema/CSGen.cpp +++ b/lib/Sema/CSGen.cpp @@ -1924,8 +1924,7 @@ namespace { OpenPackElementType(CS, locator, elementEnv)); if (result->hasError()) { auto &ctxt = CS.getASTContext(); - auto *repr = new (ctxt) PlaceholderTypeRepr(specializationArg->getLoc()); - result = PlaceholderType::get(ctxt, repr); + result = PlaceholderType::get(ctxt, specializationArg); ctxt.Diags.diagnose(lAngleLoc, diag::while_parsing_as_left_angle_bracket); } @@ -4806,11 +4805,11 @@ bool ConstraintSystem::generateConstraints( // If we have a placeholder originating from a PlaceholderTypeRepr, // tack that on to the locator. if (auto *placeholderTy = ty->getAs()) - if (auto *placeholderRepr = placeholderTy->getOriginator() - .dyn_cast()) + if (auto *typeRepr = placeholderTy->getOriginator() + .dyn_cast()) return getConstraintLocator( convertTypeLocator, - LocatorPathElt::PlaceholderType(placeholderRepr)); + LocatorPathElt::PlaceholderType(typeRepr)); return convertTypeLocator; }; diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index 0764f0b0fa04e..7a500b01bb6d1 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -1071,17 +1071,17 @@ Type ConstraintSystem::replaceInferableTypesWithTypeVars( return openUnboundGenericType(unbound->getDecl(), unbound->getParent(), locator, /*isTypeResolution=*/false); } else if (auto *placeholderTy = type->getAs()) { - if (auto *placeholderRepr = placeholderTy->getOriginator() - .dyn_cast()) { - - return createTypeVariable( - getConstraintLocator( - locator, LocatorPathElt::PlaceholderType(placeholderRepr)), - TVO_CanBindToNoEscape | TVO_PrefersSubtypeBinding | - TVO_CanBindToHole); - } - - if (auto *var = placeholderTy->getOriginator().dyn_cast()) { + if (auto *typeRepr = + placeholderTy->getOriginator().dyn_cast()) { + if (isa(typeRepr)) { + return createTypeVariable( + getConstraintLocator(locator, + LocatorPathElt::PlaceholderType(typeRepr)), + TVO_CanBindToNoEscape | TVO_PrefersSubtypeBinding | + TVO_CanBindToHole); + } + } else if (auto *var = + placeholderTy->getOriginator().dyn_cast()) { if (var->getName().hasDollarPrefix()) { auto *repr = new (type->getASTContext()) PlaceholderTypeRepr(var->getLoc()); diff --git a/lib/Sema/TypeCheckDeclPrimary.cpp b/lib/Sema/TypeCheckDeclPrimary.cpp index b90163f155b8c..2b5da8ebfc718 100644 --- a/lib/Sema/TypeCheckDeclPrimary.cpp +++ b/lib/Sema/TypeCheckDeclPrimary.cpp @@ -1172,7 +1172,8 @@ void TypeChecker::notePlaceholderReplacementTypes(Type writtenType, } if (auto *origRepr = - placeholder->getOriginator().dyn_cast()) { + placeholder->getOriginator().dyn_cast()) { + assert(isa(origRepr)); t1->getASTContext() .Diags .diagnose(origRepr->getLoc(),