This used to compile and work as expected, now the local typealias is not found or ignored.
struct T {
typealias Test = Int
}
protocol Test {
typealias Test = T.Test
}
struct S: Test {
var x: Test = 42 // error: Value of type 'Int' does not conform to specified type 'Test'
}
struct A {
typealias Value = Int
}
protocol B {
typealias Value = A.Value
typealias X = String
}
protocol NestedProtocol {
typealias _B = B
}
struct Something: NestedProtocol {
// workaround: `struct InnerTest: B` but why did it break?
struct InnerTest: _B { // conforms to `B` but all type aliases are lost
var value: Value = 42 // error: Use of undeclared type 'Value'
var x: X = "wait what?" // error Use of undeclared type 'X'
}
}
protocol X {}
protocol Y {
typealias _X = X
var x: _X { get }
}
struct Struct: Y {
// error: Value of type 'Struct.__X' does not conform to specified type 'Struct._X' (aka 'X')
var x: _X = __X()
}
extension Struct {
struct __X: _X {}
}
Because S conforms to protocol Test that as a type alias that shadows it. Give me a minute to test. All three examples are basically re-constructed examples from our app where it now errors out but previously did not.
$ swiftc --version
Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
Target: x86_64-apple-darwin18.2.0
$ cat > test.swift
struct T {
typealias Test = Int
}
protocol Test {
typealias Test = T.Test
}
struct S: Test {
var x: Test = 42 // error: Value of type 'Int' does not conform to specified type 'Test'
}
$ swiftc test.swift
test.swift:10:17: error: value of type 'Int' does not conform to specified type 'Test'
var x: Test = 42 // error: Value of type 'Int' does not conform to specified type 'Test'
^~
as! Test
$
I can verify that your next example does compile with 4.2 though.
struct T {
typealias Test = Int
}
protocol Test {
typealias Test = T.Test
var test: Test { get }
}
struct S: Test {
var test: Self.Test = ...
}
The Swift 4.2.1 compiler suggests Self.Test but since Self is only available in Swift 5 it does not work. But this is indicates that Self.Test should not be different from Test in the body of S. This is failing in playgrounds. I'll check the project again if I reduced the example correctly.
OK, then perhaps this has different behavior with Swift 5:
struct T {
typealias Test = Int
}
protocol Test {
typealias Test = T.Test
}
struct S: Test {
static func foo() { print(Test.self) }
}
S.foo() // Prints Int with Swift 4.2 (haven't tested Swift 5)
Well the first example is part of the second post in this thread, which for some reason loses the type alias. Maybe the first example should not compile, but second and third did work but now fail.