Skip to content

Commit 82fcee7

Browse files
committed
[Diagnostics] NFC: Adjust diagnostic test-cases improved by new ambiguity diagnosis
1 parent 0af9a28 commit 82fcee7

File tree

13 files changed

+38
-27
lines changed

13 files changed

+38
-27
lines changed

test/Constraints/diagnostics.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,8 +1117,10 @@ func platypus<T>(a: [T]) {
11171117
// Another case of the above.
11181118
func badTypes() {
11191119
let sequence:AnySequence<[Int]> = AnySequence() { AnyIterator() { [3] }}
1120+
// Notes, attached to declarations, explain that there is a difference between Array.init(_:) and
1121+
// RangeReplaceableCollection.init(_:) which are both applicable in this case.
11201122
let array = [Int](sequence)
1121-
// expected-error@-1 {{initializer 'init(_:)' requires the types 'Int' and '[Int]' be equivalent}}
1123+
// expected-error@-1 {{no exact matches in call to initializer}}
11221124
}
11231125

11241126
// rdar://34357545

test/Constraints/sr12964.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
protocol P {}
44
typealias T = (P) -> Void
55
let x: T! = [1, 2, 3].reversed().reduce()
6-
// expected-error@-1 {{no exact matches in call to instance method 'reduce'}}
7-
// expected-note@-2 2{{candidate has partially matching parameter list}}
6+
// expected-error@-1 {{missing arguments for parameters #1, #2 in call}}

test/Constraints/tuple_arguments.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,8 +1702,8 @@ x.map { (_: ()) in () }
17021702
// https://bugs.swift.org/browse/SR-9470
17031703
do {
17041704
func f(_: Int...) {}
1705-
let _ = [(1, 2, 3)].map(f) // expected-error {{cannot convert value of type '(Int...) -> ()' to expected argument type '((Int, Int, Int)) throws -> T'}}
1706-
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
1705+
let _ = [(1, 2, 3)].map(f) // expected-error {{no exact matches in call to instance method 'map'}}
1706+
// expected-note@-1 {{found candidate with type '(((Int, Int, Int)) throws -> _) throws -> Array<_>'}}
17071707
}
17081708

17091709
// rdar://problem/48443263 - cannot convert value of type '() -> Void' to expected argument type '(_) -> Void'

test/ImportResolution/import-resolution-overload.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ scopedFunction = 42
4646
// FIXME: Should be an error -- a type name and a function cannot overload.
4747
var _ : Int = TypeNameWins(42)
4848

49-
TypeNameWins = 42 // expected-error {{no exact matches in reference to global function 'TypeNameWins'}}
49+
TypeNameWins = 42 // expected-error {{cannot assign to immutable expression of type 'Int'}}
5050
var _ : TypeNameWins // no-warning
5151

5252
// rdar://problem/21739333

test/Misc/misc_diagnostics.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ struct MyArray<Element> {} // expected-note {{'Element' declared as parameter to
5454
class A {
5555
var a: MyArray<Int>
5656
init() {
57-
a = MyArray<Int // expected-error {{generic parameter 'Element' could not be inferred}}
58-
// expected-note@-1 {{explicitly specify the generic arguments to fix this issue}}
57+
a = MyArray<Int // expected-error {{generic parameter 'Element' could not be inferred}} expected-note {{explicitly specify the generic arguments to fix this issue}}
58+
// expected-error@-1 {{binary operator '<' cannot be applied to operands of type 'MyArray<_>.Type' and 'Int.Type'}}
59+
// expected-error@-2 {{cannot assign value of type 'Bool' to type 'MyArray<Int>'}}
5960
}
6061
}
6162

test/Sema/enum_raw_representable.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,23 @@ rdar32431165_2(E_32431165.bar)
135135
rdar32431165_2(42, E_32431165.bar)
136136
// expected-error@-1 {{cannot convert value of type 'E_32431165' to expected argument type 'String'}} {{34-34=.rawValue}}
137137

138-
E_32431165.bar == "bar"
139-
// expected-error@-1 {{cannot convert value of type 'E_32431165' to expected argument type 'String}} {{15-15=.rawValue}}
140-
141-
"bar" == E_32431165.bar
142-
// expected-error@-1 {{cannot convert value of type 'E_32431165' to expected argument type 'String}} {{24-24=.rawValue}}
138+
// TODO: In following two examples it's possible to fix a problem by either using `.rawValue` on first argument
139+
// or constructing raw representable type from second, both ways are valid.
140+
do {
141+
E_32431165.bar == "bar"
142+
// expected-error@-1 {{binary operator '==' cannot be applied to operands of type 'E_32431165' and 'String'}} expected-note@-1 {{partially matching parameter lists: (String, String)}}
143+
144+
"bar" == E_32431165.bar
145+
// expected-error@-1 {{binary operator '==' cannot be applied to operands of type 'String' and 'E_32431165'}} expected-note@-1 {{partially matching parameter lists: (String, String)}}
146+
}
143147

144-
func rdar32431165_overloaded() -> Int { 42 } // expected-note {{found candidate with type 'Int'}}
148+
func rdar32431165_overloaded() -> Int { 42 } // expected-note {{'rdar32431165_overloaded()' produces 'Int', not the expected contextual result type 'E_32431165'}}
145149
func rdar32431165_overloaded() -> String { "A" } // expected-note {{'rdar32431165_overloaded()' produces 'String', not the expected contextual result type 'E_32431165'}}
146150

147151
func test_candidate_diagnostic() {
148152
func test_argument(_: E_32431165) {}
149153

150-
let _: E_32431165 = rdar32431165_overloaded() // expected-error {{no exact matches in call to global function 'rdar32431165_overloaded'}}
154+
let _: E_32431165 = rdar32431165_overloaded() // expected-error {{no 'rdar32431165_overloaded' candidates produce the expected contextual result type 'E_32431165'}}
151155
test_argument(rdar32431165_overloaded()) // expected-error {{cannot convert value of type 'String' to expected argument type 'E_32431165'}} {{17-17=E_32431165(rawValue: }} {{42-42=) ?? <#default value#>}}
152156
}
153157

@@ -197,7 +201,8 @@ func sr8150_mutable(obj: SR8150Box) {
197201
sr8150_helper1(opt)
198202
// expected-error@-1 {{cannot convert value of type 'Bar?' to expected argument type 'Double'}} {{23-23=?.rawValue ?? <#default value#>}}
199203
sr8150_helper1(opt ?? Bar.a)
200-
// expected-error@-1 {{cannot convert value of type 'Bar' to expected argument type 'Double'}} {{20-20=(}} {{32-32=).rawValue}}
204+
// expected-error@-1 {{no exact matches in call to global function 'sr8150_helper1'}}
205+
// expected-note@-2 {{candidate expects value of type 'Bar' for parameter #0}} {{20-20=(}} {{32-32=).rawValue}}
201206
let _: Double? = opt
202207
// expected-error@-1 {{cannot convert value of type 'Bar?' to specified type 'Double?'}} {{25-25=?.rawValue}}
203208
}

test/decl/protocol/req/recursion.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public struct S<A: P> where A.T == S<A> { // expected-error {{circular reference
5454

5555
func g(a: S<A>) {
5656
f(a: id(t: a))
57-
// expected-error@-1 {{conflicting arguments to generic parameter 'T' ('S<A>' vs. 'A.T' (associated type of protocol 'P'))}}
57+
// expected-error@-1 {{cannot convert value of type 'S<A>' to expected argument type 'A.T'}}
5858
_ = S<A>.self
5959
}
6060

test/expr/unary/keypath/salvage-with-other-type-errors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protocol Bindable: class { }
5252
extension Bindable {
5353
func test<Value>(to targetKeyPath: ReferenceWritableKeyPath<Self, Value>, change: Value?) {
5454
if self[keyPath:targetKeyPath] != change {
55-
// expected-error@-1 {{operator function '!=' requires that 'Value' conform to 'Equatable'}}
55+
// expected-error@-1 {{binary operator '!=' cannot be applied to operands of type 'Value' and 'Value?'}}
5656
self[keyPath: targetKeyPath] = change!
5757
}
5858
}

test/stdlib/KeyPathAppending.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,20 @@ func mismatchedAppends<T, U, V>(readOnlyLeft: KeyPath<T, U>,
5858
// expected-note@-2 {{arguments to generic parameter 'Root' ('T' and 'V') are expected to be equal}}
5959

6060
_ = readOnlyRight.appending(path: referenceLeft)
61-
// expected-error@-1 {{cannot convert value of type 'ReferenceWritableKeyPath<T, U>' to expected argument type 'ReferenceWritableKeyPath<V, U>'}}
62-
// expected-note@-2 {{arguments to generic parameter 'Root' ('T' and 'V') are expected to be equal}}
61+
// expected-error@-1 {{no exact matches in call to instance method 'appending'}}
6362

6463
_ = writableRight.appending(path: readOnlyLeft)
65-
// expected-error@-1 {{instance method 'appending(path:)' requires that 'KeyPath<U, V>' inherit from 'KeyPath<U, T>'}}
64+
// expected-error@-1 {{no exact matches in call to instance method 'appending'}}
6665

6766
_ = writableRight.appending(path: writableLeft)
6867
// expected-error@-1 {{cannot convert value of type 'WritableKeyPath<T, U>' to expected argument type 'WritableKeyPath<V, U>'}}
6968
// expected-note@-2 {{arguments to generic parameter 'Root' ('T' and 'V') are expected to be equal}}
7069

7170
_ = writableRight.appending(path: referenceLeft)
72-
// expected-error@-1 {{cannot convert value of type 'ReferenceWritableKeyPath<T, U>' to expected argument type 'ReferenceWritableKeyPath<V, U>'}}
73-
// expected-note@-2 {{arguments to generic parameter 'Root' ('T' and 'V') are expected to be equal}}
71+
// expected-error@-1 {{no exact matches in call to instance method 'appending'}}
7472

7573
_ = referenceRight.appending(path: readOnlyLeft)
76-
// expected-error@-1 {{instance method 'appending(path:)' requires that 'KeyPath<U, V>' inherit from 'KeyPath<U, T>'}}
74+
// expected-error@-1 {{no exact matches in call to instance method 'appending'}}
7775

7876
_ = referenceRight.appending(path: writableLeft)
7977
// expected-error@-1 {{cannot convert value of type 'WritableKeyPath<T, U>' to expected argument type 'WritableKeyPath<V, U>'}}

test/stdlib/StringDiagnostics.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func testAmbiguousStringComparisons(s: String) {
4848

4949
// Shouldn't suggest 'as' in a pattern-matching context, as opposed to all these other situations
5050
if case nsString = "" {} // expected-error{{expression pattern of type 'NSString' cannot match values of type 'String'}}
51+
// expected-note@-1 {{overloads for '~=' exist with these partially matching parameter lists: (Substring, String)}}
5152
}
5253

5354
func testStringDeprecation(hello: String) {

test/stdlib/UnicodeScalarDiagnostics.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ func test_UnicodeScalarDoesNotImplementArithmetic(_ us: UnicodeScalar, i: Int) {
1313
let a4 = "a" / "b" // expected-error {{binary operator '/' cannot be applied to two 'String' operands}}
1414

1515
let b1 = us + us // expected-error {{referencing operator function '+' on 'RangeReplaceableCollection' requires that 'UnicodeScalar' (aka 'Unicode.Scalar') conform to 'RangeReplaceableCollection'}}
16-
let b2 = us - us // expected-error {{referencing operator function '-' on 'FloatingPoint' requires that 'UnicodeScalar' (aka 'Unicode.Scalar') conform to 'FloatingPoint'}}
17-
let b3 = us * us // expected-error {{referencing operator function '*' on 'FloatingPoint' requires that 'UnicodeScalar' (aka 'Unicode.Scalar') conform to 'FloatingPoint'}}
18-
let b4 = us / us // expected-error {{referencing operator function '/' on 'FloatingPoint' requires that 'UnicodeScalar' (aka 'Unicode.Scalar') conform to 'FloatingPoint'}}
16+
let b2 = us - us // expected-error {{binary operator '-' cannot be applied to two 'UnicodeScalar' (aka 'Unicode.Scalar') operands}}
17+
let b3 = us * us // expected-error {{binary operator '*' cannot be applied to two 'UnicodeScalar' (aka 'Unicode.Scalar') operands}}
18+
let b4 = us / us // expected-error {{binary operator '/' cannot be applied to two 'UnicodeScalar' (aka 'Unicode.Scalar') operands}}
1919

2020
let c1 = us + i // expected-error {{cannot convert value of type 'UnicodeScalar' (aka 'Unicode.Scalar') to expected argument type 'Int'}}
2121
let c2 = us - i // expected-error {{cannot convert value of type 'UnicodeScalar' (aka 'Unicode.Scalar') to expected argument type 'Int'}}

test/type/protocol_composition.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ takesP1AndP2([AnyObject & protocol_composition.P1 & P2]())
174174
takesP1AndP2([AnyObject & P1 & protocol_composition.P2]())
175175
takesP1AndP2([DoesNotExist & P1 & P2]()) // expected-error {{cannot find 'DoesNotExist' in scope}}
176176
takesP1AndP2([Swift.DoesNotExist & P1 & P2]()) // expected-error {{module 'Swift' has no member named 'DoesNotExist'}}
177+
// expected-error@-1 {{binary operator '&' cannot be applied to operands of type 'UInt8' and 'P1.Protocol'}}
178+
// expected-error@-2 {{binary operator '&' cannot be applied to operands of type 'UInt8' and 'P2.Protocol'}}
179+
// expected-note@-3 2 {{overloads for '&' exist with these partially matching parameter lists}}
180+
177181

178182
typealias T08 = P1 & inout P2 // expected-error {{'inout' may only be used on parameters}}
179183
typealias T09 = P1 & __shared P2 // expected-error {{'__shared' may only be used on parameters}}

validation-test/Sema/type_checker_perf/slow/rdar53589951.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
22
// REQUIRES: tools-release,no_asan
3+
// REQUIRES: rdar36854536
34

45
class Color {
56
init(hue: Double, saturation: Double, brightness: Double, alpha: Double) {}

0 commit comments

Comments
 (0)