Skip to content

Commit 2e4d315

Browse files
author
Harlan Haskins
authored
Merge pull request #30287 from HassanElDesouky/SR-12311
[SR-12311] Improve diagnostic for read-only properties
2 parents 883d546 + d0b6d9f commit 2e4d315

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,8 +1973,8 @@ WARNING(protocol_usable_from_inline_warn,none,
19731973
"protocol %select{refined|used}0 by '@usableFromInline' protocol "
19741974
"should be '@usableForInline' or public", (bool))
19751975
ERROR(protocol_property_must_be_computed_var,none,
1976-
"immutable property requirement must be declared as 'var' with a "
1977-
"'{ get }' specifier", ())
1976+
"protocols cannot require properties to be immutable; declare read-only "
1977+
"properties by using 'var' with a '{ get }' specifier", ())
19781978
ERROR(protocol_property_must_be_computed,none,
19791979
"property in protocol must have explicit { get } or { get set } specifier",
19801980
())

test/decl/protocol/protocols.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protocol Test {
1717
var subminor : Int // expected-error {{property in protocol must have explicit { get } or { get set } specifier}} {{21-21= { get <#set#> \}}}
1818
static var staticProperty: Int // expected-error{{property in protocol must have explicit { get } or { get set } specifier}} {{33-33= { get <#set#> \}}}
1919

20-
let bugfix // expected-error {{type annotation missing in pattern}} expected-error {{immutable property requirement must be declared as 'var' with a '{ get }' specifier}}
20+
let bugfix // expected-error {{type annotation missing in pattern}} expected-error {{protocols cannot require properties to be immutable; declare read-only properties by using 'var' with a '{ get }' specifier}}
2121
var comment // expected-error {{type annotation missing in pattern}} expected-error {{property in protocol must have explicit { get } or { get set } specifier}}
2222
}
2323

@@ -458,7 +458,7 @@ protocol ShouldntCrash {
458458
let fullName: String { get } // expected-error {{'let' declarations cannot be computed properties}} {{3-6=var}}
459459

460460
// <rdar://problem/17200672> Let in protocol causes unclear errors and crashes
461-
let fullName2: String // expected-error {{immutable property requirement must be declared as 'var' with a '{ get }' specifier}} {{3-6=var}} {{24-24= { get \}}}
461+
let fullName2: String // expected-error {{protocols cannot require properties to be immutable; declare read-only properties by using 'var' with a '{ get }' specifier}} {{3-6=var}} {{24-24= { get \}}}
462462

463463
// <rdar://problem/16789886> Assert on protocol property requirement without a type
464464
var propertyWithoutType { get } // expected-error {{type annotation missing in pattern}}
@@ -514,7 +514,7 @@ class C4 : P4 { // expected-error {{type 'C4' does not conform to protocol 'P4'}
514514
// <rdar://problem/25185722> Crash with invalid 'let' property in protocol
515515
protocol LetThereBeCrash {
516516
let x: Int
517-
// expected-error@-1 {{immutable property requirement must be declared as 'var' with a '{ get }' specifier}} {{13-13= { get \}}}
517+
// expected-error@-1 {{protocols cannot require properties to be immutable; declare read-only properties by using 'var' with a '{ get }' specifier}} {{13-13= { get \}}}
518518
// expected-note@-2 {{declared here}}
519519
}
520520

test/decl/var/properties.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ protocol ProtocolWillSetDidSet4 {
884884
var a: Int { didSet willSet } // expected-error {{property in protocol must have explicit { get } or { get set } specifier}} {{14-32={ get <#set#> \}}} expected-error 2 {{expected get or set in a protocol property}}
885885
}
886886
protocol ProtocolWillSetDidSet5 {
887-
let a: Int { didSet willSet } // expected-error {{immutable property requirement must be declared as 'var' with a '{ get }' specifier}} {{3-6=var}} {{13-13= { get \}}} {{none}} expected-error 2 {{expected get or set in a protocol property}} expected-error {{'let' declarations cannot be computed properties}} {{3-6=var}}
887+
let a: Int { didSet willSet } // expected-error {{protocols cannot require properties to be immutable; declare read-only properties by using 'var' with a '{ get }' specifier}} {{3-6=var}} {{13-13= { get \}}} {{none}} expected-error 2 {{expected get or set in a protocol property}} expected-error {{'let' declarations cannot be computed properties}} {{3-6=var}}
888888
}
889889

890890
var globalDidsetWillSet: Int { // expected-error {{non-member observing properties require an initializer}}

test/decl/var/static_var.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ protocol P { // expected-note{{extended type declared here}}
177177
class var v2: Int { get } // expected-error {{class properties are only allowed within classes; use 'static' to declare a requirement fulfilled by either a static or class property}} {{3-8=static}}
178178
static final var v3: Int { get } // expected-error {{only classes and class members may be marked with 'final'}}
179179

180-
static let l1: Int // expected-error {{immutable property requirement must be declared as 'var' with a '{ get }' specifier}}
181-
class let l2: Int // expected-error {{class properties are only allowed within classes; use 'static' to declare a requirement fulfilled by either a static or class property}} {{3-8=static}} expected-error {{immutable property requirement must be declared as 'var' with a '{ get }' specifier}}
180+
static let l1: Int // expected-error {{protocols cannot require properties to be immutable; declare read-only properties by using 'var' with a '{ get }' specifier}}
181+
class let l2: Int // expected-error {{class properties are only allowed within classes; use 'static' to declare a requirement fulfilled by either a static or class property}} {{3-8=static}} expected-error {{protocols cannot require properties to be immutable; declare read-only properties by using 'var' with a '{ get }' specifier}}
182182
}
183183

184184
extension P {

0 commit comments

Comments
 (0)