Skip to content

Commit 10f5376

Browse files
authored
Merge pull request #17633 from DougGregor/fix-apply-without-throws-set-4.2
[4.2] Ensure that apply expressions have their "throws" bit set
2 parents 09dc7b7 + 54f972f commit 10f5376

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

lib/AST/ProtocolConformance.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,6 @@ ProtocolConformanceRef::getTypeWitnessByName(Type type,
134134
ProtocolConformanceRef conformance,
135135
Identifier name,
136136
LazyResolver *resolver) {
137-
// For an archetype, retrieve the nested type with the appropriate
138-
// name. There are no conformance tables.
139-
if (auto archetype = type->getAs<ArchetypeType>()) {
140-
return archetype->getNestedType(name);
141-
}
142-
143137
// Find the named requirement.
144138
AssociatedTypeDecl *assocType = nullptr;
145139
auto members = conformance.getRequirement()->lookupDirect(name);
@@ -153,8 +147,15 @@ ProtocolConformanceRef::getTypeWitnessByName(Type type,
153147
if (!assocType)
154148
return nullptr;
155149

156-
if (conformance.isAbstract())
150+
if (conformance.isAbstract()) {
151+
// For an archetype, retrieve the nested type with the appropriate
152+
// name. There are no conformance tables.
153+
if (auto archetype = type->getAs<ArchetypeType>()) {
154+
return archetype->getNestedType(name);
155+
}
156+
157157
return DependentMemberType::get(type, assocType);
158+
}
158159

159160
auto concrete = conformance.getConcrete();
160161
if (!concrete->hasTypeWitness(assocType, resolver)) {

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,7 @@ createDefaultConstructor(ClangImporter::Implementation &Impl,
11881188

11891189
auto call = CallExpr::createImplicit(context, zeroInitializerRef, {}, {});
11901190
call->setType(selfType);
1191+
call->setThrows(false);
11911192

11921193
auto assign = new (context) AssignExpr(lhs, SourceLoc(), call,
11931194
/*implicit*/ true);

lib/Sema/TypeCheckError.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ class AbstractFunction {
134134
fn = conversion->getSubExpr()->getValueProvidingExpr();
135135
} else if (auto conversion = dyn_cast<BindOptionalExpr>(fn)) {
136136
fn = conversion->getSubExpr()->getValueProvidingExpr();
137+
// Look through optional injections
138+
} else if (auto injection = dyn_cast<InjectIntoOptionalExpr>(fn)) {
139+
fn = injection->getSubExpr()->getValueProvidingExpr();
137140
// Look through function conversions.
138141
} else if (auto conversion = dyn_cast<FunctionConversionExpr>(fn)) {
139142
fn = conversion->getSubExpr()->getValueProvidingExpr();

test/Constraints/generic_super_constraint.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@ func bar<T, U>(_ x: U, y: T) -> (Derived, Int) where U: Base<T>, U: Derived {
1717
// expected-error@+1{{cannot convert return expression}}
1818
return (x, y)
1919
}
20+
21+
// SR-7551 captures a crash on this code.
22+
class IntegerClass : ExpressibleByIntegerLiteral, Equatable {
23+
required init(integerLiteral value: Int) { }
24+
static func ==(lhs: IntegerClass, rhs: IntegerClass) -> Bool { return true }
25+
}
26+
27+
func foo<T: IntegerClass>(_ num: T) { let _ = num != 0 }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// Used to crash with: apply expression is not marked as throwing or
4+
// non-throwing
5+
struct SR5427 : Error {}
6+
func sr5427(op: (() throws -> Void)?) rethrows { try op?() }
7+
try? sr5427(op: { throw SR5427() })

0 commit comments

Comments
 (0)