Skip to content

Commit 1f85c04

Browse files
authored
Merge pull request #31961 from CodaFi/setternalia
2 parents 11a6d2b + d42ac62 commit 1f85c04

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,8 +2338,9 @@ diagnoseMatch(ModuleDecl *module, NormalProtocolConformance *conformance,
23382338
diags.diagnose(witness, diag::protocol_witness_settable_conflict);
23392339
if (auto VD = dyn_cast<VarDecl>(witness)) {
23402340
if (VD->hasStorage()) {
2341-
auto PBD = VD->getParentPatternBinding();
2342-
diag.fixItReplace(PBD->getStartLoc(), getTokenText(tok::kw_var));
2341+
if (auto PBD = VD->getParentPatternBinding()) {
2342+
diag.fixItReplace(PBD->getStartLoc(), getTokenText(tok::kw_var));
2343+
}
23432344
}
23442345
}
23452346
break;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public protocol OtherOS {
2+
var name: String { get }
3+
}
4+
5+
public struct Linux: OtherOS {
6+
public let name = "Linux"
7+
}

test/decl/protocol/req/witness_fix_its.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
// RUN: %target-typecheck-verify-swift
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -o %t/OtherOS.swiftmodule -module-name OtherOS %S/Inputs/witness_fix_its_other_module.swift -parse-as-library
3+
// RUN: %target-typecheck-verify-swift -I %t/
24

35
prefix operator ^^^
46
postfix operator ^^^^
57

8+
import OtherOS
9+
610
protocol Foo {
711
var bar1: Int { get set } // expected-note {{protocol requires property 'bar1' with type 'Int'; do you want to add a stub?}}
812
static var bar2: Int { get set } // expected-note {{protocol requires property 'bar2' with type 'Int'; do you want to add a stub?}}
@@ -34,3 +38,12 @@ protocol Foo1 {
3438
struct ConformsToFoo1: Foo1 { // expected-error {{type 'ConformsToFoo1' does not conform to protocol 'Foo1'}}
3539
subscript(value: Bool) -> Bool { return false } // expected-note {{candidate is not settable, but protocol requires it}}{{none}}
3640
}
41+
42+
// Don't crash or try to fixup get/set mismatches in other modules
43+
// This protocol requirement must conflict with the one in
44+
// witness_fix_its_other_module.swift.
45+
protocol RenameableProtocol {
46+
var name: String { get set } // expected-note {{protocol requires property 'name' with type 'String'; do you want to add a stub?}}
47+
}
48+
49+
extension Linux: RenameableProtocol {} // expected-error {{type 'Linux' does not conform to protocol 'RenameableProtocol'}}

0 commit comments

Comments
 (0)