Skip to content

Commit

Permalink
Merge pull request #32337 from LucianoPAlmeida/SR-12955-avoid-error-t…
Browse files Browse the repository at this point in the history
…ype-diag

[SR-12955] [Sema] Don't diagnose invalid conversion if fnType has error
  • Loading branch information
LucianoPAlmeida authored Jun 12, 2020
2 parents 0d57f3b + b2e8a60 commit 55e2506
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,16 @@ getObjCObjectRepresentable(Type type, const DeclContext *dc) {
static std::pair<ForeignRepresentableKind, ProtocolConformance *>
getForeignRepresentable(Type type, ForeignLanguage language,
const DeclContext *dc) {
// Local function that simply produces a failing result.
auto failure = []() -> std::pair<ForeignRepresentableKind,
ProtocolConformance *> {
return { ForeignRepresentableKind::None, nullptr };
};

// If type has an error let's fail early.
if (type->hasError())
return failure();

// Look through one level of optional type, but remember that we did.
bool wasOptional = false;
if (auto valueType = type->getOptionalObjectType()) {
Expand All @@ -2222,12 +2232,6 @@ getForeignRepresentable(Type type, ForeignLanguage language,
return { representable, nullptr };
}

// Local function that simply produces a failing result.
auto failure = []() -> std::pair<ForeignRepresentableKind,
ProtocolConformance *> {
return { ForeignRepresentableKind::None, nullptr };
};

// Function types.
if (auto functionType = type->getAs<FunctionType>()) {
// Cannot handle throwing functions.
Expand Down
4 changes: 4 additions & 0 deletions lib/Sema/TypeCheckType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2675,6 +2675,10 @@ Type TypeResolver::resolveASTFunctionType(
}

auto fnTy = FunctionType::get(params, outputTy, extInfo);

if (fnTy->hasError())
return fnTy;

// If the type is a block or C function pointer, it must be representable in
// ObjC.
switch (representation) {
Expand Down
5 changes: 5 additions & 0 deletions test/expr/closure/inference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,8 @@ let cc = SR8563 { (_: (Int)) in }

cc((1)) // Ok
cc(1) // Ok

// SR-12955
func SR12955() {
let f: @convention(c) (T) -> Void // expected-error {{cannot find type 'T' in scope}}
}

0 comments on commit 55e2506

Please sign in to comment.