@@ -1972,15 +1972,21 @@ Expr *PreCheckExpression::simplifyTypeConstructionWithLiteralArg(Expr *E) {
1972
1972
Type type;
1973
1973
if (typeExpr->getTypeLoc ().wasValidated ()) {
1974
1974
type = typeExpr->getTypeLoc ().getType ();
1975
- } else if ( auto *rep = typeExpr-> getTypeRepr ()) {
1975
+ } else {
1976
1976
TypeResolutionOptions options (TypeResolverContext::InExpression);
1977
1977
options |= TypeResolutionFlags::AllowUnboundGenerics;
1978
- auto resolution = TypeResolution::forContextual (DC);
1979
- type = resolution.resolveType (rep, options);
1980
- typeExpr->getTypeLoc ().setType (type);
1978
+
1979
+ auto &typeLoc = typeExpr->getTypeLoc ();
1980
+ bool hadError =
1981
+ TC.validateType (typeLoc, TypeResolution::forContextual (DC), options);
1982
+
1983
+ if (hadError)
1984
+ return nullptr ;
1985
+
1986
+ type = typeLoc.getType ();
1981
1987
}
1982
1988
1983
- if (!type)
1989
+ if (!type || !type-> getAnyNominal () )
1984
1990
return nullptr ;
1985
1991
1986
1992
// Don't bother to convert deprecated selector syntax.
@@ -1989,16 +1995,13 @@ Expr *PreCheckExpression::simplifyTypeConstructionWithLiteralArg(Expr *E) {
1989
1995
return nullptr ;
1990
1996
}
1991
1997
1992
- ConformanceCheckOptions options;
1993
- options |= ConformanceCheckFlags::InExpression;
1994
- options |= ConformanceCheckFlags::SkipConditionalRequirements;
1995
-
1996
- auto result = TypeChecker::conformsToProtocol (type, protocol, DC, options);
1997
- if (!result || !result->isConcrete ())
1998
- return nullptr ;
1999
-
2000
- return CoerceExpr::forLiteralInit (TC.Context , argExpr, call->getSourceRange (),
2001
- typeExpr->getTypeLoc ());
1998
+ auto *NTD = type->getAnyNominal ();
1999
+ SmallVector<ProtocolConformance *, 2 > conformances;
2000
+ return NTD->lookupConformance (DC->getParentModule (), protocol, conformances)
2001
+ ? CoerceExpr::forLiteralInit (TC.Context , argExpr,
2002
+ call->getSourceRange (),
2003
+ typeExpr->getTypeLoc ())
2004
+ : nullptr ;
2002
2005
}
2003
2006
2004
2007
// / Pre-check the expression, validating any types that occur in the
0 commit comments