Files
swift-mirror/test/decl/protocol/fixits_missing_protocols_in_context.swift
Suyash Srijan 79b0a7ef75 [CSDiagnostics] Emit fix-its to insert requirement stubs for missing protocols in context (#33628)
* [CSDiagnostics] Emit fix-its to insert requirement stubs in editor mode for missing protocols in context

* [CSDiagnostics] Only include missing requirements in stub fix-it for missing protocols in context

The conforming type may already have declarations that could satisfy a requirement, so we shouldn't include it in the fix-it
2020-08-26 02:05:29 +01:00

46 lines
1.2 KiB
Swift

// RUN: %target-swift-frontend -typecheck -diagnostics-editor-mode -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 'P?'}}
// expected-note@-2 {{add missing conformance to 'P' to class 'C'}} {{8-8=: P}} {{10-10=\n func method() {\n <#code#>\n \}\n\n var 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 'P?'}}
// expected-note@-2 {{add missing conformance to 'P' to class 'C1'}} {{9-9=: P}} {{11-11=\n var 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 'P?'}}
// expected-note@-2 {{add missing conformance to 'P' to class 'C2'}} {{9-9=: P}}
}
func method() {}
var property: Int = 0
}