mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
When generating a stub fix-it for a protocol conformance or implementation extension, Swift will now evaluate whether the context allows the declaration of stored properties and, if so, will suggest one. It will also use the `let` keyword instead of `var` if the property has no setter.
46 lines
1.2 KiB
Swift
46 lines
1.2 KiB
Swift
// RUN: %target-swift-frontend -typecheck -verify %s
|
|
|
|
// Test that we emit fix-its to insert requirement stubs for the missing protocol conformance, in addition to adding the conformance.
|
|
|
|
protocol P {
|
|
func method()
|
|
var property: Int { get }
|
|
}
|
|
|
|
class C {
|
|
var p: P?
|
|
|
|
func assign() {
|
|
p = self
|
|
// expected-error@-1 {{cannot assign value of type 'C' to type '(any P)?'}}
|
|
// expected-note@-2 {{add missing conformance to 'P' to class 'C'}} {{-4:8-8=: P}} {{-4:10-10=\n func method() {\n <#code#>\n \}\n\n let property: Int\n}}
|
|
}
|
|
}
|
|
|
|
// Test that we don't emit fix-it to insert a requirement stub if there is already a satisfying witness.
|
|
|
|
class C1 {
|
|
var p: P?
|
|
|
|
func assign() {
|
|
p = self
|
|
// expected-error@-1 {{cannot assign value of type 'C1' to type '(any P)?'}}
|
|
// expected-note@-2 {{add missing conformance to 'P' to class 'C1'}} {{-4:9-9=: P}} {{-4:11-11=\n let property: Int\n}}
|
|
}
|
|
|
|
func method() {}
|
|
}
|
|
|
|
class C2 {
|
|
var p: P?
|
|
|
|
func assign() {
|
|
p = self
|
|
// expected-error@-1 {{cannot assign value of type 'C2' to type '(any P)?'}}
|
|
// expected-note@-2 {{add missing conformance to 'P' to class 'C2'}} {{-4:9-9=: P}}
|
|
}
|
|
|
|
func method() {}
|
|
var property: Int = 0
|
|
}
|