@@ -1903,9 +1903,9 @@ namespace {
19031903 // / introduce them as an explicit generic arguments constraint.
19041904 // /
19051905 // / \returns true if resolving any of the specialization types failed.
1906- bool addSpecializationConstraint (
1907- ConstraintLocator *locator, Type boundType ,
1908- ArrayRef<TypeRepr *> specializationArgs) {
1906+ void addSpecializationConstraint (ConstraintLocator *locator, Type boundType,
1907+ SourceLoc lAngleLoc ,
1908+ ArrayRef<TypeRepr *> specializationArgs) {
19091909 // Resolve each type.
19101910 SmallVector<Type, 2 > specializationArgTypes;
19111911 auto options =
@@ -1916,61 +1916,36 @@ namespace {
19161916 options |= TypeResolutionFlags::AllowPackReferences;
19171917 elementEnv = OuterExpansions.back ();
19181918 }
1919- const auto result = TypeResolution::resolveContextualType (
1919+ auto result = TypeResolution::resolveContextualType (
19201920 specializationArg, CurDC, options,
19211921 // Introduce type variables for unbound generics.
19221922 OpenUnboundGenericType (CS, locator),
19231923 HandlePlaceholderType (CS, locator),
19241924 OpenPackElementType (CS, locator, elementEnv));
1925- if (result->hasError ())
1926- return true ;
1927-
1925+ if (result->hasError ()) {
1926+ auto &ctxt = CS.getASTContext ();
1927+ auto *repr = new (ctxt) PlaceholderTypeRepr (specializationArg->getLoc ());
1928+ result = PlaceholderType::get (ctxt, repr);
1929+ ctxt.Diags .diagnose (lAngleLoc,
1930+ diag::while_parsing_as_left_angle_bracket);
1931+ }
19281932 specializationArgTypes.push_back (result);
19291933 }
19301934
1931- CS. addConstraint (
1932- ConstraintKind::ExplicitGenericArguments, boundType,
1933- PackType::get (CS.getASTContext (), specializationArgTypes),
1934- locator );
1935- return false ;
1935+ auto constraint = Constraint::create (
1936+ CS, ConstraintKind::ExplicitGenericArguments, boundType,
1937+ PackType::get (CS.getASTContext (), specializationArgTypes), locator);
1938+ CS. addUnsolvedConstraint (constraint );
1939+ CS. activateConstraint (constraint) ;
19361940 }
19371941
19381942 Type visitUnresolvedSpecializeExpr (UnresolvedSpecializeExpr *expr) {
19391943 auto baseTy = CS.getType (expr->getSubExpr ());
1940-
1941- if (baseTy->isTypeVariableOrMember ()) {
1942- return baseTy;
1943- }
1944-
1945- // We currently only support explicit specialization of generic types.
1946- // FIXME: We could support explicit function specialization.
1947- auto &de = CS.getASTContext ().Diags ;
1948- if (baseTy->is <AnyFunctionType>()) {
1949- de.diagnose (expr->getSubExpr ()->getLoc (),
1950- diag::cannot_explicitly_specialize_generic_function);
1951- de.diagnose (expr->getLAngleLoc (),
1952- diag::while_parsing_as_left_angle_bracket);
1953- return Type ();
1954- }
1955-
1956- if (AnyMetatypeType *meta = baseTy->getAs <AnyMetatypeType>()) {
1957- auto *overloadLocator = CS.getConstraintLocator (expr->getSubExpr ());
1958- if (addSpecializationConstraint (overloadLocator,
1959- meta->getInstanceType (),
1960- expr->getUnresolvedParams ())) {
1961- return Type ();
1962- }
1963-
1964- return baseTy;
1965- }
1966-
1967- // FIXME: If the base type is a type variable, constrain it to a metatype
1968- // of a bound generic type.
1969- de.diagnose (expr->getSubExpr ()->getLoc (),
1970- diag::not_a_generic_definition);
1971- de.diagnose (expr->getLAngleLoc (),
1972- diag::while_parsing_as_left_angle_bracket);
1973- return Type ();
1944+ auto *overloadLocator = CS.getConstraintLocator (expr->getSubExpr ());
1945+ addSpecializationConstraint (
1946+ overloadLocator, baseTy->getMetatypeInstanceType (),
1947+ expr->getLAngleLoc (), expr->getUnresolvedParams ());
1948+ return baseTy;
19741949 }
19751950
19761951 Type visitSequenceExpr (SequenceExpr *expr) {
@@ -4080,10 +4055,9 @@ namespace {
40804055
40814056 // Add explicit generic arguments, if there were any.
40824057 if (expr->getGenericArgsRange ().isValid ()) {
4083- if (addSpecializationConstraint (
4084- CS.getConstraintLocator (expr), macroRefType,
4085- expr->getGenericArgs ()))
4086- return Type ();
4058+ addSpecializationConstraint (CS.getConstraintLocator (expr), macroRefType,
4059+ expr->getGenericArgsRange ().Start ,
4060+ expr->getGenericArgs ());
40874061 }
40884062
40894063 // Form the applicable-function constraint. The result type
0 commit comments