forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvalid.swift
81 lines (54 loc) · 2.37 KB
/
invalid.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// RUN: %target-typecheck-verify-swift
func bet() where A : B {} // expected-error {{'where' clause cannot be attached to a non-generic declaration}}
typealias gimel where A : B // expected-error {{'where' clause cannot be attached to a non-generic declaration}}
// expected-error@-1 {{expected '=' in typealias declaration}}
class dalet where A : B {} // expected-error {{'where' clause cannot be attached to a non-generic declaration}}
protocol he where A : B { // expected-error {{'where' clause cannot be attached to a protocol declaration}}
associatedtype vav where A : B // expected-error {{'where' clause cannot be attached to an associated type declaration}}
}
struct Lunch<T> {
struct Dinner<U> {
var leftovers: T
var transformation: (T) -> U
}
}
class Deli<Spices> {
class Pepperoni {}
struct Sausage {}
}
struct Pizzas<Spices> {
class NewYork {
}
class DeepDish {
}
}
class HotDog {
}
struct Pepper {}
struct ChiliFlakes {}
func eatDinnerConcrete(d: Pizzas<ChiliFlakes>.NewYork,
t: Deli<ChiliFlakes>.Pepperoni) {
}
func eatDinnerConcrete(d: Pizzas<Pepper>.DeepDish,
t: Deli<Pepper>.Pepperoni) {
}
func badDiagnostic1() {
_ = Lunch<Pizzas<Pepper>.NewYork>.Dinner<HotDog>( // expected-error {{expression type 'Lunch<Pizzas<Pepper>.NewYork>.Dinner<HotDog>' is ambiguous without more context}}
leftovers: Pizzas<ChiliFlakes>.NewYork(),
transformation: { _ in HotDog() })
}
func badDiagnostic2() {
let firstCourse = Pizzas<ChiliFlakes>.NewYork()
var dinner = Lunch<Pizzas<ChiliFlakes>.NewYork>.Dinner<HotDog>(
leftovers: firstCourse,
transformation: { _ in HotDog() })
let topping = Deli<Pepper>.Pepperoni()
eatDinnerConcrete(d: firstCourse, t: topping)
// expected-error@-1 {{cannot invoke 'eatDinnerConcrete' with an argument list of type '(d: Pizzas<ChiliFlakes>.NewYork, t: Deli<Pepper>.Pepperoni)'}}
// expected-note@-2 {{overloads for 'eatDinnerConcrete' exist with these partially matching parameter lists: (d: Pizzas<ChiliFlakes>.NewYork, t: Deli<ChiliFlakes>.Pepperoni), (d: Pizzas<Pepper>.DeepDish, t: Deli<Pepper>.Pepperoni)}}
}
// Real error is that we cannot infer the generic parameter from context
func takesAny(_ a: Any) {}
func badDiagnostic3() {
takesAny(Deli.self) // expected-error {{argument type 'Deli<_>.Type' does not conform to expected type 'Any'}}
}