Skip to content

Commit 55e2506

Browse files
Merge pull request swiftlang#32337 from LucianoPAlmeida/SR-12955-avoid-error-type-diag
[SR-12955] [Sema] Don't diagnose invalid conversion if fnType has error
2 parents 0d57f3b + b2e8a60 commit 55e2506

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

lib/AST/Type.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,16 @@ getObjCObjectRepresentable(Type type, const DeclContext *dc) {
22082208
static std::pair<ForeignRepresentableKind, ProtocolConformance *>
22092209
getForeignRepresentable(Type type, ForeignLanguage language,
22102210
const DeclContext *dc) {
2211+
// Local function that simply produces a failing result.
2212+
auto failure = []() -> std::pair<ForeignRepresentableKind,
2213+
ProtocolConformance *> {
2214+
return { ForeignRepresentableKind::None, nullptr };
2215+
};
2216+
2217+
// If type has an error let's fail early.
2218+
if (type->hasError())
2219+
return failure();
2220+
22112221
// Look through one level of optional type, but remember that we did.
22122222
bool wasOptional = false;
22132223
if (auto valueType = type->getOptionalObjectType()) {
@@ -2222,12 +2232,6 @@ getForeignRepresentable(Type type, ForeignLanguage language,
22222232
return { representable, nullptr };
22232233
}
22242234

2225-
// Local function that simply produces a failing result.
2226-
auto failure = []() -> std::pair<ForeignRepresentableKind,
2227-
ProtocolConformance *> {
2228-
return { ForeignRepresentableKind::None, nullptr };
2229-
};
2230-
22312235
// Function types.
22322236
if (auto functionType = type->getAs<FunctionType>()) {
22332237
// Cannot handle throwing functions.

lib/Sema/TypeCheckType.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,6 +2675,10 @@ Type TypeResolver::resolveASTFunctionType(
26752675
}
26762676

26772677
auto fnTy = FunctionType::get(params, outputTy, extInfo);
2678+
2679+
if (fnTy->hasError())
2680+
return fnTy;
2681+
26782682
// If the type is a block or C function pointer, it must be representable in
26792683
// ObjC.
26802684
switch (representation) {

test/expr/closure/inference.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,8 @@ let cc = SR8563 { (_: (Int)) in }
7373

7474
cc((1)) // Ok
7575
cc(1) // Ok
76+
77+
// SR-12955
78+
func SR12955() {
79+
let f: @convention(c) (T) -> Void // expected-error {{cannot find type 'T' in scope}}
80+
}

0 commit comments

Comments
 (0)