Compile bug in XCode 10 beta?

When compiling the following code with Swift 4.1


class Test {
    var str = "MyString"
}

protocol TestProtocol {
    var str: String { get }
}

class MyTest: Test, TestProtocol { }

var x: (Test & TestProtocol) = MyTest()

x.str


it compiles without any problem on XCode 9.4, but XCode 10 fails with this error message:

error: XCode10Bug.playground:11:1: error: ambiguous use of 'str'
x.str
^

XCode10Bug.playground:4:9: note: found this candidate
    var str: String { get }
        ^


Is this somehow intended behavior, or should I report this as a bug?

Why do you need to define str in the protocol ?


Effectively, that seems to create an ambiguity, as Test does not conform to TestProtocol: which x do you mean ?


If you comment out var x in Protocol, everything OK.


And of course the following works:

protocol TestProtocol {
    var str: String { get }
//    func setX()
}

class Test: TestProtocol {
    var str = "MyString"
}
var x4 = Test()
print(x4.str)


I tried also the following :

class Test {
    var str = "MyString"
}

protocol TestProtocol {
//    var str: String { get }
    func setX()
}

class MyTest: Test, TestProtocol {
    func setX() {
        self.str = "New String"
    }
  
}

var x4: (Test & TestProtocol) = MyTest()

print(x4.str)
x4.setX()
print(x4.str)

And get correct output

MyString

New String


So, that does not seem to be a bug but a stricter test of consistency.

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
Compile bug in XCode 10 beta?
 
 
Q