Created
August 8, 2019 07:52
-
-
Save omochi/36e1182d51214d98681710125d436163 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
ビルド & 実行 | |
# a.swiftmoduleの生成 | |
$ swiftc -emit-module a.swift | |
# liba.dylibの生成 | |
$ swiftc -emit-library a.swift | |
# b.swiftの実行 | |
$ swift -I . -L. -la b.swift | |
*/ | |
// -------------------------------- | |
// a.swift | |
// -------------------------------- | |
public protocol P {} | |
public struct S : P {} | |
open class A<T> { | |
public init() {} | |
} | |
extension A : P where T : P { | |
} | |
open class C { | |
public init() {} | |
} | |
public func test1(_ x: Any) { | |
if x is P { | |
print("type of x (\(type(of: x))) conforms P") | |
} else { | |
print("type of x (\(type(of: x))) does not conforms P") | |
} | |
} | |
// -------------------------------- | |
// b.swift | |
// -------------------------------- | |
import a | |
//public class B<U> : A<Int> {} | |
// b.swift:5:15: error: conflicting conformance of 'B<U>' to protocol 'P'; there cannot be more than one conformance, even with different conditional bounds | |
// 親クラスAがすでにPのcondconfを持っているから駄目らしい | |
//extension B : P where U : P {} | |
class D<U> : C {} | |
extension D : P where U : P {} | |
let a1 = A<Int>() | |
test1(a1) // not conform | |
let a2 = A<S>() | |
test1(a2) // conditionally conform | |
let d1 = D<Int>() | |
test1(d1) // not conform | |
let d2 = D<S>() | |
test1(d2) // conditionally conform |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment