Files
swift-mirror/test/Compatibility/string_collection.swift
Doug Gregor f7bccb0e68 [Type checker] Downgrade some "redundant conformance" errors to warnings.
When an extension introduces a conformance that already exists, the
type checker will reject the conformance and then ignore it. In cases
where the original conformance is in the same module as the type or
protocol (but the new, redundant conformance is in some other module),
downgrade this error to a warning. This helps with library-evolution
cases where a library omitted a particular conformance for one of its
own types/protocols in a previous version, then introduces it in a new
version.

The specific driver for this is the conformance of String to
Collection, which affects source compatibility. Fixes
rdar://problem/31104415.
2017-05-01 13:22:15 -07:00

16 lines
572 B
Swift

// RUN: %target-typecheck-verify-swift -swift-version 3
extension String : Collection { // expected-warning{{conformance of 'String' to protocol 'Collection' was already stated in the type's module 'Swift'}}
subscript (i: Index) -> String { // expected-note{{subscript 'subscript' will not be used to satisfy the conformance to 'Collection'}}
get { return self }
set { }
}
var isEmpty: Bool { return false } // expected-note{{var 'isEmpty' will not be used to satisfy the conformance to 'Collection'}}
}
func testStringOps(s: String) {
_ = s.isEmpty
}