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