The code above is a simplified version of code in the SwipeCellKit (https://github.com/SwipeCellKit/SwipeCellKit). I am not the author of SwipeCellKit, but I was surprised to find out that XCode 10 compiles Swift 4.1 code differently than XCode 9.4 does. I didn't update to Swift 4.2 yet, so I didn't expect compile breaking changes in the same minor version!
Also, in the context of SwipeCellKit, the actual usage makes more sense, and IMHO this stricter check of consistency shouldn't actually result into rejecting this program.
Even in my minimized version, there is only one implementation of str to choose from (the one defined in Test)... So there shouldn't be any ambiguity! The TestProtocol itself just requires a var str to exist, therefore line 9 of my original code example does compile without any issues!
In a slightly extended version, it might make sense to define a protocol composition type like this:
class Test {
var str = "MyString"
var str2 = "str2"
}
protocol TestProtocol {
var str: String { get }
var str3: String { get }
}
class MyTest: Test, TestProtocol { var str3 = "str3" }
class MyTest2: TestProtocol {
var str = "different"
var str3 = "mystr3"
}
var x: (Test & TestProtocol) = MyTest()
x.str
x.str2
x.str3
var x2: TestProtocol = MyTest()
x2.str
// No access to x2.str2!
x2.str3
var y: TestProtocol = MyTest2()
y.str
y.str3