|
| 1 | +// RUN: %target-typecheck-verify-swift -enable-experimental-bound-generic-extensions |
| 2 | + |
| 3 | +extension Array<Int> { |
| 4 | + func someIntFuncOnArray() {} |
| 5 | +} |
| 6 | + |
| 7 | +let _ = [0, 1, 2].someIntFuncOnArray() |
| 8 | + |
| 9 | +extension [Character] { |
| 10 | + func makeString() -> String { fatalError() } |
| 11 | +} |
| 12 | + |
| 13 | +let _ = ["a", "b", "c"].makeString() |
| 14 | +let _ = [1, 2, 3].makeString() // expected-error 3 {{cannot convert value of type 'Int' to expected element type 'Character'}} |
| 15 | + |
| 16 | +extension Set<_> {} // expected-error {{cannot extend a type that contains placeholders}} |
| 17 | + |
| 18 | +// https://bugs.swift.org/browse/SR-4875 |
| 19 | + |
| 20 | +struct Foo<T, U> { |
| 21 | + var x: T |
| 22 | + var y: U |
| 23 | +} |
| 24 | + |
| 25 | +typealias IntFoo<U> = Foo<Int, U> |
| 26 | + |
| 27 | +extension IntFoo where U == Int { |
| 28 | + func hello() { |
| 29 | + print("hello") |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +Foo(x: "test", y: 1).hello() |
| 34 | + |
| 35 | +struct MyType<TyA, TyB> { |
| 36 | + var a : TyA, b : TyB |
| 37 | +} |
| 38 | + |
| 39 | +typealias A<T1, T2> = MyType<T2, T1> |
| 40 | + |
| 41 | +extension A {} |
| 42 | + |
| 43 | +extension A<Float, Int> {} |
| 44 | +extension A<Void, Void> {} |
| 45 | + |
| 46 | +struct Tree<T> { |
| 47 | + struct Branch<B> { |
| 48 | + struct Nest<N> { |
| 49 | + struct Egg {} |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +extension Tree.Branch.Nest.Egg { static func tweet() {} } |
| 55 | +extension Tree<Int>.Branch.Nest.Egg { static func twoot() {} } |
| 56 | +extension Tree<Int>.Branch<String>.Nest.Egg { static func twote() {} } |
| 57 | +extension Tree<Int>.Branch<String>.Nest<Void>.Egg { static func twite() {} } |
| 58 | + |
| 59 | +func testNestedExtensions() { |
| 60 | + do { |
| 61 | + Tree<Void>.Branch<Void>.Nest<Void>.Egg.tweet() |
| 62 | + } |
| 63 | + |
| 64 | + do { |
| 65 | + Tree<Int>.Branch<Void>.Nest<Void>.Egg.twoot() |
| 66 | + Tree<Int>.Branch<Int>.Nest<Void>.Egg.twoot() |
| 67 | + Tree<Int>.Branch<Int>.Nest<Int>.Egg.twoot() |
| 68 | + } |
| 69 | + |
| 70 | + do { |
| 71 | + Tree<Int>.Branch<String>.Nest<Void>.Egg.twote() |
| 72 | + Tree<Int>.Branch<String>.Nest<Float>.Egg.twote() |
| 73 | + } |
| 74 | + |
| 75 | + Tree<Int>.Branch<String>.Nest<Void>.Egg.twite() |
| 76 | +} |
0 commit comments