Skip to content

Commit 3ce754e

Browse files
committed
Sema: Fix crash on static -vs- non-static witness mismatch with deserialized witness
Deserialized computed properties don't get a PatternBindingDecl apparently. Fixes <rdar://problem/68241758>.
1 parent 4ab7933 commit 3ce754e

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,13 +2311,16 @@ diagnoseMatch(ModuleDecl *module, NormalProtocolConformance *conformance,
23112311
if (auto FD = dyn_cast<FuncDecl>(witness)) {
23122312
loc = FD->getStaticLoc();
23132313
} else if (auto VD = dyn_cast<VarDecl>(witness)) {
2314-
loc = VD->getParentPatternBinding()->getStaticLoc();
2314+
if (auto PBD = VD->getParentPatternBinding()) {
2315+
loc = PBD->getStaticLoc();
2316+
}
23152317
} else if (auto SD = dyn_cast<SubscriptDecl>(witness)) {
23162318
loc = SD->getStaticLoc();
23172319
} else {
23182320
llvm_unreachable("Unexpected witness");
23192321
}
2320-
diag.fixItRemove(loc);
2322+
if (loc.isValid())
2323+
diag.fixItRemove(loc);
23212324
} else {
23222325
diag.fixItInsert(witness->getAttributeInsertionLoc(true), "static ");
23232326
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public struct TimeZone {
2+
public static var current: TimeZone { return TimeZone() }
3+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %S/Inputs/deserialized_witness_mismatch_other.swift -emit-module-path %t/deserialized_witness_mismatch_other.swiftmodule
3+
// RUN: %target-swift-frontend -I %t/ %s -typecheck -verify
4+
5+
// Deserialized computed properties don't have a PatternBindingDecl, so
6+
// make sure we don't expect to find one.
7+
8+
import deserialized_witness_mismatch_other
9+
10+
protocol HasCurrent {
11+
var current: Self { get }
12+
// expected-note@-1 {{protocol requires property 'current' with type 'TimeZone'; do you want to add a stub?}}
13+
}
14+
15+
extension TimeZone : HasCurrent {}
16+
// expected-error@-1 {{type 'TimeZone' does not conform to protocol 'HasCurrent'}}

0 commit comments

Comments
 (0)