Skip to content

Use The Location of the Pattern Binding in Codable Fixit #34294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/Sema/DerivedConformanceCodable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,10 @@ deriveBodyDecodable_init(AbstractFunctionDecl *initDecl, void *) {
diag::decodable_property_init_or_codingkeys_explicit,
varDecl->getName());
}
varDecl->diagnose(diag::decodable_make_property_mutable)
.fixItReplace(varDecl->getAttributeInsertionLoc(true), "var");
if (auto *PBD = varDecl->getParentPatternBinding()) {
varDecl->diagnose(diag::decodable_make_property_mutable)
.fixItReplace(PBD->getLoc(), "var");
}

continue;
}
Expand Down
28 changes: 28 additions & 0 deletions test/decl/protocol/special/coding/immutable_property.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: %target-typecheck-verify-swift -verify-ignore-unknown

struct Foo : Codable {
let x1: String = ""
// expected-warning@-1 {{immutable property will not be decoded because it is declared with an initial value which cannot be overwritten}}
// expected-note@-2 {{set the initial value via the initializer or explicitly define a CodingKeys enum including a 'x1' case to silence this warning}}
// expected-note@-3 {{make the property mutable instead}}{{3-6=var}}

public let x2: String = ""
// expected-warning@-1 {{immutable property will not be decoded because it is declared with an initial value which cannot be overwritten}}
// expected-note@-2 {{set the initial value via the initializer or explicitly define a CodingKeys enum including a 'x2' case to silence this warning}}
// expected-note@-3 {{make the property mutable instead}}{{10-13=var}}

internal let x3: String = ""
// expected-warning@-1 {{immutable property will not be decoded because it is declared with an initial value which cannot be overwritten}}
// expected-note@-2 {{set the initial value via the initializer or explicitly define a CodingKeys enum including a 'x3' case to silence this warning}}
// expected-note@-3 {{make the property mutable instead}}{{12-15=var}}

fileprivate let x4: String = ""
// expected-warning@-1 {{immutable property will not be decoded because it is declared with an initial value which cannot be overwritten}}
// expected-note@-2 {{set the initial value via the initializer or explicitly define a CodingKeys enum including a 'x4' case to silence this warning}}
// expected-note@-3 {{make the property mutable instead}}{{15-18=var}}

private let x5: String = ""
// expected-warning@-1 {{immutable property will not be decoded because it is declared with an initial value which cannot be overwritten}}
// expected-note@-2 {{set the initial value via the initializer or explicitly define a CodingKeys enum including a 'x5' case to silence this warning}}
// expected-note@-3 {{make the property mutable instead}}{{11-14=var}}
}