Skip to content

Commit fcd364d

Browse files
authored
Merge pull request swiftlang#34012 from slavapestov/fix-witness-matching-crash-no-pbd
Sema: Fix crash on static -vs- non-static witness mismatch with deserialized witness
2 parents 04ddca3 + cf2d0d3 commit fcd364d

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
@@ -2374,13 +2374,16 @@ diagnoseMatch(ModuleDecl *module, NormalProtocolConformance *conformance,
23742374
if (auto FD = dyn_cast<FuncDecl>(witness)) {
23752375
loc = FD->getStaticLoc();
23762376
} else if (auto VD = dyn_cast<VarDecl>(witness)) {
2377-
loc = VD->getParentPatternBinding()->getStaticLoc();
2377+
if (auto PBD = VD->getParentPatternBinding()) {
2378+
loc = PBD->getStaticLoc();
2379+
}
23782380
} else if (auto SD = dyn_cast<SubscriptDecl>(witness)) {
23792381
loc = SD->getStaticLoc();
23802382
} else {
23812383
llvm_unreachable("Unexpected witness");
23822384
}
2383-
diag.fixItRemove(loc);
2385+
if (loc.isValid())
2386+
diag.fixItRemove(loc);
23842387
} else {
23852388
diag.fixItInsert(witness->getAttributeInsertionLoc(true), "static ");
23862389
}
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)