Skip to content

Commit a253c40

Browse files
authored
Merge pull request #34294 from CodaFi/patterns-as-compiler-bugs
2 parents daca3d9 + 4351bd3 commit a253c40

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lib/Sema/DerivedConformanceCodable.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,10 @@ deriveBodyDecodable_init(AbstractFunctionDecl *initDecl, void *) {
799799
diag::decodable_property_init_or_codingkeys_explicit,
800800
varDecl->getName());
801801
}
802-
varDecl->diagnose(diag::decodable_make_property_mutable)
803-
.fixItReplace(varDecl->getAttributeInsertionLoc(true), "var");
802+
if (auto *PBD = varDecl->getParentPatternBinding()) {
803+
varDecl->diagnose(diag::decodable_make_property_mutable)
804+
.fixItReplace(PBD->getLoc(), "var");
805+
}
804806

805807
continue;
806808
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %target-typecheck-verify-swift -verify-ignore-unknown
2+
3+
struct Foo : Codable {
4+
let x1: String = ""
5+
// expected-warning@-1 {{immutable property will not be decoded because it is declared with an initial value which cannot be overwritten}}
6+
// expected-note@-2 {{set the initial value via the initializer or explicitly define a CodingKeys enum including a 'x1' case to silence this warning}}
7+
// expected-note@-3 {{make the property mutable instead}}{{3-6=var}}
8+
9+
public let x2: String = ""
10+
// expected-warning@-1 {{immutable property will not be decoded because it is declared with an initial value which cannot be overwritten}}
11+
// expected-note@-2 {{set the initial value via the initializer or explicitly define a CodingKeys enum including a 'x2' case to silence this warning}}
12+
// expected-note@-3 {{make the property mutable instead}}{{10-13=var}}
13+
14+
internal let x3: String = ""
15+
// expected-warning@-1 {{immutable property will not be decoded because it is declared with an initial value which cannot be overwritten}}
16+
// expected-note@-2 {{set the initial value via the initializer or explicitly define a CodingKeys enum including a 'x3' case to silence this warning}}
17+
// expected-note@-3 {{make the property mutable instead}}{{12-15=var}}
18+
19+
fileprivate let x4: String = ""
20+
// expected-warning@-1 {{immutable property will not be decoded because it is declared with an initial value which cannot be overwritten}}
21+
// expected-note@-2 {{set the initial value via the initializer or explicitly define a CodingKeys enum including a 'x4' case to silence this warning}}
22+
// expected-note@-3 {{make the property mutable instead}}{{15-18=var}}
23+
24+
private let x5: String = ""
25+
// expected-warning@-1 {{immutable property will not be decoded because it is declared with an initial value which cannot be overwritten}}
26+
// expected-note@-2 {{set the initial value via the initializer or explicitly define a CodingKeys enum including a 'x5' case to silence this warning}}
27+
// expected-note@-3 {{make the property mutable instead}}{{11-14=var}}
28+
}

0 commit comments

Comments
 (0)