Skip to content

Commit dcc940b

Browse files
authored
Merge pull request #61586 from slavapestov/fix-61517
Sema: Fix crash when pre-checking expression of the form P(<<literal>>) where P is a protocol
2 parents 4205446 + fbab90b commit dcc940b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/Sema/PreCheckExpr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,8 +2119,7 @@ Expr *PreCheckExpression::simplifyTypeConstructionWithLiteralArg(Expr *E) {
21192119
return nullptr;
21202120
}
21212121

2122-
SmallVector<ProtocolConformance *, 2> conformances;
2123-
return castTy->getAnyNominal()->lookupConformance(protocol, conformances)
2122+
return DC->getParentModule()->lookupConformance(castTy, protocol)
21242123
? CoerceExpr::forLiteralInit(getASTContext(), literal,
21252124
call->getSourceRange(),
21262125
typeExpr->getTypeRepr())

test/Constraints/protocols.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,3 +533,16 @@ func f1_58231(x: Int) -> P_58231 {
533533
func f2_58231(x: Int) -> P_58231? {
534534
return S_58231() // expected-error{{return expression of type 'S_58231' does not conform to 'P_58231'}}
535535
}
536+
537+
// https://github.com/apple/swift/issues/61517
538+
539+
protocol P_61517 {
540+
init()
541+
init(_: Bool)
542+
}
543+
544+
_ = P_61517() // expected-error{{type 'any P_61517' cannot be instantiated}}
545+
_ = P_61517(false) // expected-error{{type 'any P_61517' cannot be instantiated}}
546+
547+
_ = P_61517.init() // expected-error{{type 'any P_61517' cannot be instantiated}}
548+
_ = P_61517.init(false) // expected-error{{type 'any P_61517' cannot be instantiated}}

0 commit comments

Comments
 (0)