Skip to content

Commit 780612c

Browse files
authored
Merge pull request swiftlang#22800 from slavapestov/witness-access-check-crash
Sema: Fix crashes in witness access control checking
2 parents 57c017a + cde5c6f commit 780612c

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,16 +2463,19 @@ void ConformanceChecker::recordTypeWitness(AssociatedTypeDecl *assocType,
24632463
if (checkWitnessAccess(assocType, typeDecl, &isSetter)) {
24642464
assert(!isSetter);
24652465

2466-
// Avoid relying on the lifetime of 'this'.
2466+
// Note: you must not capture 'this' in the below closure.
24672467
const DeclContext *DC = this->DC;
2468+
auto requiredAccessScope = getRequiredAccessScope();
2469+
24682470
diagnoseOrDefer(assocType, false,
2469-
[this, DC, typeDecl](NormalProtocolConformance *conformance) {
2471+
[DC, requiredAccessScope, typeDecl](
2472+
NormalProtocolConformance *conformance) {
24702473
AccessLevel requiredAccess =
2471-
getRequiredAccessScope().requiredAccessForDiagnostics();
2474+
requiredAccessScope.requiredAccessForDiagnostics();
24722475
auto proto = conformance->getProtocol();
24732476
auto protoAccessScope = proto->getFormalAccessScope(DC);
24742477
bool protoForcesAccess =
2475-
getRequiredAccessScope().hasEqualDeclContextWith(protoAccessScope);
2478+
requiredAccessScope.hasEqualDeclContextWith(protoAccessScope);
24762479
auto diagKind = protoForcesAccess
24772480
? diag::type_witness_not_accessible_proto
24782481
: diag::type_witness_not_accessible_type;
@@ -2546,11 +2549,6 @@ void ConformanceChecker::recordTypeWitness(AssociatedTypeDecl *assocType,
25462549
aliasDecl->getAttrs().add(attr);
25472550
}
25482551

2549-
bool unused;
2550-
assert(TC.Context.hadError() ||
2551-
!checkWitnessAccess(assocType, aliasDecl, &unused));
2552-
(void)unused;
2553-
25542552
if (nominal == DC) {
25552553
nominal->addMember(aliasDecl);
25562554
} else {

test/Compatibility/attr_escaping.swift

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: not %target-swift-frontend -typecheck %s -swift-version 4
2+
// RUN: not %target-swift-frontend -typecheck %s -swift-version 5
3+
4+
public struct Horse : OptionSet {
5+
typealias Element = Horse // this was not public...
6+
public static let horse = Horse()
7+
}

0 commit comments

Comments
 (0)