Skip to content

Commit d9594c7

Browse files
committed
[TypeChecker] NFC: Adjust tests improved by new approach for ambiguity diagnosis
1 parent cf3f52c commit d9594c7

18 files changed

+47
-208
lines changed

test/AutoDiff/Sema/differentiable_func_type.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,20 @@ extension Vector: Differentiable where T: Differentiable {
175175
mutating func move(along direction: TangentVector) { fatalError() }
176176
}
177177

178+
// expected-note@+1 2 {{candidate requires that 'Int' conform to 'Differentiable' (requirement specified as 'T' == 'Differentiable')}}
178179
func inferredConformancesGeneric<T, U>(_: @differentiable (Vector<T>) -> Vector<U>) {}
179180

181+
// expected-note @+5 2 {{candidate requires that 'Int' conform to 'Differentiable' (requirement specified as 'T' == 'Differentiable')}}
180182
// expected-error @+4 {{generic signature requires types 'Vector<T>' and 'Vector<T>.TangentVector' to be the same}}
181183
// expected-error @+3 {{generic signature requires types 'Vector<U>' and 'Vector<U>.TangentVector' to be the same}}
182184
// expected-error @+2 {{parameter type 'Vector<T>' does not conform to 'Differentiable' and satisfy 'Vector<T> == Vector<T>.TangentVector', but the enclosing function type is '@differentiable(linear)'}}
183185
// expected-error @+1 {{result type 'Vector<U>' does not conform to 'Differentiable' and satisfy 'Vector<U> == Vector<U>.TangentVector', but the enclosing function type is '@differentiable(linear)'}}
184186
func inferredConformancesGenericLinear<T, U>(_: @differentiable(linear) (Vector<T>) -> Vector<U>) {}
185187

186188
func nondiff(x: Vector<Int>) -> Vector<Int> {}
187-
// expected-error @+1 {{global function 'inferredConformancesGeneric' requires that 'Int' conform to 'Differentiable}}
189+
// expected-error @+1 {{no exact matches in call to global function 'inferredConformancesGeneric'}}
188190
inferredConformancesGeneric(nondiff)
189-
// expected-error @+1 {{global function 'inferredConformancesGenericLinear' requires that 'Int' conform to 'Differentiable}}
191+
// expected-error @+1 {{no exact matches in call to global function 'inferredConformancesGenericLinear'}}
190192
inferredConformancesGenericLinear(nondiff)
191193

192194
func diff(x: Vector<Float>) -> Vector<Float> {}
@@ -208,16 +210,16 @@ extension Linear: Differentiable where T: Differentiable, T == T.TangentVector {
208210
typealias TangentVector = Self
209211
}
210212

211-
// expected-note @+1 2 {{where 'T' = 'Int'}}
213+
// expected-note @+1 2 {{candidate requires that 'Int' conform to 'Differentiable' (requirement specified as 'T' == 'Differentiable')}}
212214
func inferredConformancesGeneric<T, U>(_: @differentiable (Linear<T>) -> Linear<U>) {}
213215

214-
// expected-note @+1 2 {{where 'T' = 'Int'}}
216+
// expected-note @+1 2 {{candidate requires that 'Int' conform to 'Differentiable' (requirement specified as 'T' == 'Differentiable')}}
215217
func inferredConformancesGenericLinear<T, U>(_: @differentiable(linear) (Linear<T>) -> Linear<U>) {}
216218

217219
func nondiff(x: Linear<Int>) -> Linear<Int> {}
218-
// expected-error @+1 {{global function 'inferredConformancesGeneric' requires that 'Int' conform to 'Differentiable}}
220+
// expected-error @+1 {{no exact matches in call to global function 'inferredConformancesGeneric'}}
219221
inferredConformancesGeneric(nondiff)
220-
// expected-error @+1 {{global function 'inferredConformancesGenericLinear' requires that 'Int' conform to 'Differentiable}}
222+
// expected-error @+1 {{no exact matches in call to global function 'inferredConformancesGenericLinear'}}
221223
inferredConformancesGenericLinear(nondiff)
222224

223225
func diff(x: Linear<Float>) -> Linear<Float> {}

test/ClangImporter/objc_factory_method.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func testNSErrorFactoryMethod(_ path: String) throws {
7575
}
7676

7777
func testNonInstanceTypeFactoryMethod(_ s: String) {
78-
_ = NSObjectFactory(string: s) // expected-error{{argument passed to call that takes no arguments}}
78+
_ = NSObjectFactory(string: s) // expected-error{{no exact matches in call to initializer}}
7979
}
8080

8181
func testUseOfFactoryMethod(_ queen: Bee) {

test/ClangImporter/objc_implicit_with.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func testNSErrorFactoryMethod(_ path: String) throws {
4343
}
4444

4545
func testNonInstanceTypeFactoryMethod(_ s: String) {
46-
_ = NSObjectFactory(string: s) // expected-error{{argument passed to call that takes no arguments}}
46+
_ = NSObjectFactory(string: s) // expected-error{{no exact matches in call to initializer}}
4747
}
4848

4949
func testUseOfFactoryMethod(_ queen: Bee) {

test/Constraints/argument_matching.swift

Lines changed: 3 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,167 +1465,8 @@ _ = acceptTuple2(tuple1)
14651465
_ = acceptTuple2((1, "hello", 3.14159))
14661466

14671467

1468-
func generic_and_missing_label(x: Int) {}
1469-
func generic_and_missing_label<T>(x: T) {}
1468+
func generic_and_missing_label(x: Int) {} // expected-note {{incorrect labels for candidate (have: '(_:)', expected: '(x:)')}}
1469+
func generic_and_missing_label<T>(x: T) {} // expected-note {{incorrect labels for candidate (have: '(_:)', expected: '(x:)')}}
14701470

14711471
generic_and_missing_label(42)
1472-
// expected-error@-1 {{missing argument label 'x:' in call}} {{27-27=x: }}
1473-
1474-
// -------------------------------------------
1475-
// Curried functions
1476-
// -------------------------------------------
1477-
1478-
func f7(_ a: Int) -> (_ b: Int) -> Int {
1479-
return { b in a+b }
1480-
}
1481-
1482-
_ = f7(1)(1)
1483-
f7(1.0)(2) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1484-
1485-
f7(1)(1.0) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1486-
f7(1)(b: 1.0) // expected-error{{extraneous argument label 'b:' in call}}
1487-
// expected-error@-1 {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1488-
1489-
let f10 = f7(2)
1490-
_ = f10(1)
1491-
f10(10) // expected-warning {{result of call to function returning 'Int' is unused}}
1492-
f10(1.0) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1493-
f10(b: 1.0) // expected-error {{extraneous argument label 'b:' in call}}
1494-
// expected-error@-1 {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1495-
1496-
1497-
class CurriedClass {
1498-
func method1() {}
1499-
func method2(_ a: Int) -> (_ b : Int) -> () { return { b in () } }
1500-
func method3(_ a: Int, b : Int) {} // expected-note 3 {{'method3(_:b:)' declared here}}
1501-
}
1502-
1503-
let c = CurriedClass()
1504-
_ = c.method1
1505-
c.method1(1) // expected-error {{argument passed to call that takes no arguments}}
1506-
_ = c.method2(1)
1507-
_ = c.method2(1.0) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1508-
c.method2(1)(2)
1509-
c.method2(1)(c: 2) // expected-error {{extraneous argument label 'c:' in call}}
1510-
c.method2(1)(c: 2.0) // expected-error {{extraneous argument label 'c:' in call}}
1511-
// expected-error@-1 {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1512-
c.method2(1)(2.0) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1513-
c.method2(1.0)(2) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1514-
c.method2(1.0)(2.0) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1515-
// expected-error@-1 {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1516-
1517-
CurriedClass.method1(c)()
1518-
_ = CurriedClass.method1(c)
1519-
CurriedClass.method1(c)(1) // expected-error {{argument passed to call that takes no arguments}}
1520-
CurriedClass.method1(2.0)(1) // expected-error {{cannot convert value of type 'Double' to expected argument type 'CurriedClass'}}
1521-
// expected-error@-1:27 {{argument passed to call that takes no arguments}}
1522-
1523-
CurriedClass.method2(c)(32)(b: 1) // expected-error{{extraneous argument label 'b:' in call}}
1524-
_ = CurriedClass.method2(c)
1525-
_ = CurriedClass.method2(c)(32)
1526-
_ = CurriedClass.method2(1,2) // expected-error {{extra argument in call}}
1527-
// expected-error@-1 {{instance member 'method2' cannot be used on type 'CurriedClass'; did you mean to use a value of this type instead?}}
1528-
CurriedClass.method2(c)(1.0)(b: 1) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1529-
// expected-error@-1 {{extraneous argument label 'b:' in call}}
1530-
CurriedClass.method2(c)(1)(1.0) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1531-
CurriedClass.method2(c)(2)(c: 1.0) // expected-error {{extraneous argument label 'c:'}}
1532-
// expected-error@-1 {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1533-
1534-
CurriedClass.method3(c)(32, b: 1)
1535-
_ = CurriedClass.method3(c)
1536-
_ = CurriedClass.method3(c)(1, 2) // expected-error {{missing argument label 'b:' in call}} {{32-32=b: }}
1537-
_ = CurriedClass.method3(c)(1, b: 2)(32) // expected-error {{cannot call value of non-function type '()'}}
1538-
_ = CurriedClass.method3(1, 2) // expected-error {{instance member 'method3' cannot be used on type 'CurriedClass'; did you mean to use a value of this type instead?}}
1539-
// expected-error@-1 {{missing argument label 'b:' in call}}
1540-
CurriedClass.method3(c)(1.0, b: 1) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1541-
CurriedClass.method3(c)(1) // expected-error {{missing argument for parameter 'b' in call}}
1542-
CurriedClass.method3(c)(c: 1.0) // expected-error {{incorrect argument labels in call (have 'c:', expected '_:b:')}}
1543-
// expected-error@-1 {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1544-
// expected-error@-2 {{missing argument for parameter #1 in call}}
1545-
1546-
1547-
extension CurriedClass {
1548-
func f() {
1549-
method3(1, b: 2)
1550-
method3() // expected-error {{missing arguments for parameters #1, 'b' in call}} {{13-13=<#Int#>, b: <#Int#>}}
1551-
method3(42) // expected-error {{missing argument for parameter 'b' in call}}
1552-
method3(self)
1553-
// expected-error@-1:13 {{cannot convert value of type 'CurriedClass' to expected argument type 'Int'}}
1554-
// expected-error@-2:17 {{missing argument for parameter 'b' in call}} {{17-17=, b: <#Int#>}}
1555-
}
1556-
}
1557-
1558-
extension CurriedClass {
1559-
func m1(_ a : Int, b : Int) {}
1560-
1561-
func m2(_ a : Int) {}
1562-
}
1563-
1564-
// <rdar://problem/23718816> QoI: "Extra argument" error when accidentally currying a method
1565-
CurriedClass.m1(2, b: 42) // expected-error {{instance member 'm1' cannot be used on type 'CurriedClass'; did you mean to use a value of this type instead?}}
1566-
1567-
1568-
// <rdar://problem/22108559> QoI: Confusing error message when calling an instance method as a class method
1569-
CurriedClass.m2(12) // expected-error {{instance member 'm2' cannot be used on type 'CurriedClass'; did you mean to use a value of this type instead?}}
1570-
1571-
// -------------------------------------------
1572-
// Multiple label errors
1573-
// -------------------------------------------
1574-
1575-
func testLabelErrorsBasic() {
1576-
func f(_ aa: Int, _ bb: Int, cc: Int, dd: Int, ee: Int, ff: Int) {}
1577-
1578-
// 1 wrong
1579-
f(0, 1, ccx: 2, dd: 3, ee: 4, ff: 5)
1580-
// expected-error@-1 {{incorrect argument label in call (have '_:_:ccx:dd:ee:ff:', expected '_:_:cc:dd:ee:ff:')}} {{11-14=cc}} {{none}}
1581-
1582-
// 1 missing
1583-
f(0, 1, 2, dd: 3, ee: 4, ff: 5)
1584-
// expected-error@-1 {{missing argument label 'cc:' in call}} {{11-11=cc: }} {{none}}
1585-
1586-
// 1 extra
1587-
f(aa: 0, 1, cc: 2, dd: 3, ee: 4, ff: 5)
1588-
// expected-error@-1 {{extraneous argument label 'aa:' in call}} {{5-9=}} {{none}}
1589-
1590-
// 1 ooo
1591-
f(0, 1, dd: 3, cc: 2, ee: 4, ff: 5)
1592-
// expected-error@-1 {{argument 'cc' must precede argument 'dd'}} {{16-23=}} {{11-11=cc: 2, }} {{none}}
1593-
1594-
// 2 wrong
1595-
f(0, 1, ccx: 2, ddx: 3, ee: 4, ff: 5)
1596-
// expected-error@-1 {{incorrect argument labels in call (have '_:_:ccx:ddx:ee:ff:', expected '_:_:cc:dd:ee:ff:')}} {{11-14=cc}} {{19-22=dd}} {{none}}
1597-
1598-
// 2 missing
1599-
f(0, 1, 2, 3, ee: 4, ff: 5)
1600-
// expected-error@-1 {{missing argument labels 'cc:dd:' in call}} {{11-11=cc: }} {{14-14=dd: }} {{none}}
1601-
1602-
// 2 extra
1603-
f(aa: 0, bb: 1, cc: 2, dd: 3, ee: 4, ff: 5)
1604-
// expected-error@-1 {{extraneous argument labels 'aa:bb:' in call}} {{5-9=}} {{12-16=}} {{none}}
1605-
1606-
// 2 ooo
1607-
f(0, 1, dd: 3, cc: 2, ff: 5, ee: 4)
1608-
// expected-error@-1 {{argument 'cc' must precede argument 'dd'}} {{16-23=}} {{11-11=cc: 2, }} {{none}}
1609-
1610-
// 1 wrong + 1 missing
1611-
f(0, 1, ccx: 2, 3, ee: 4, ff: 5)
1612-
// expected-error@-1 {{incorrect argument labels in call (have '_:_:ccx:_:ee:ff:', expected '_:_:cc:dd:ee:ff:')}} {{11-14=cc}} {{19-19=dd: }} {{none}}
1613-
1614-
// 1 wrong + 1 extra
1615-
f(aa: 0, 1, ccx: 2, dd: 3, ee: 4, ff: 5)
1616-
// expected-error@-1 {{incorrect argument labels in call (have 'aa:_:ccx:dd:ee:ff:', expected '_:_:cc:dd:ee:ff:')}} {{5-9=}} {{15-18=cc}} {{none}}
1617-
1618-
// 1 wrong + 1 ooo
1619-
f(0, 1, ccx: 2, dd: 3, ff: 5, ee: 4)
1620-
// expected-error@-1 {{incorrect argument labels in call (have '_:_:ccx:dd:ff:ee:', expected '_:_:cc:dd:ee:ff:')}} {{11-14=cc}} {{26-28=ee}} {{33-35=ff}} {{none}}
1621-
}
1622-
1623-
struct DiagnoseAllLabels {
1624-
func f(aa: Int, bb: Int, cc: Int..., dd: Int, ee: Int = 0, ff: Int = 0) {}
1625-
1626-
func test() {
1627-
f(aax: 0, bbx: 1, cc: 21, 22, 23, dd: 3, ff: 5) // expected-error {{incorrect argument labels in call (have 'aax:bbx:cc:_:_:dd:ff:', expected 'aa:bb:cc:_:_:dd:ff:')}} {{7-10=aa}} {{15-18=bb}} {{none}}
1628-
1629-
f(aax: 0, bbx: 1, dd: 3, ff: 5) // expected-error {{incorrect argument labels in call (have 'aax:bbx:dd:ff:', expected 'aa:bb:dd:ff:')}} {{7-10=aa}} {{15-18=bb}} {{none}}
1630-
}
1631-
}
1472+
// expected-error@-1 {{no exact matches in call to global function 'generic_and_missing_label'}}

test/Constraints/closures.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,6 @@ r32432145 { _,_ in
562562
// rdar://problem/30106822 - Swift ignores type error in closure and presents a bogus error about the caller
563563
[1, 2].first { $0.foo = 3 }
564564
// expected-error@-1 {{value of type 'Int' has no member 'foo'}}
565-
// expected-error@-2 {{cannot convert value of type '()' to closure result type 'Bool'}}
566565

567566
// rdar://problem/32433193, SR-5030 - Higher-order function diagnostic mentions the wrong contextual type conversion problem
568567
protocol A_SR_5030 {
@@ -827,7 +826,7 @@ func rdar_40537960() {
827826
}
828827

829828
var arr: [S] = []
830-
_ = A(arr, fn: { L($0.v) }) // expected-error {{cannot convert value of type 'L' to closure result type 'R<P>'}}
829+
_ = A(arr, fn: { L($0.v) })
831830
// expected-error@-1 {{generic parameter 'P' could not be inferred}}
832831
// expected-note@-2 {{explicitly specify the generic arguments to fix this issue}} {{8-8=<[S], <#P: P_40537960#>>}}
833832
}

test/Constraints/diagnostics.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,9 @@ enum Color {
407407
static var svar: Color { return .Red }
408408
}
409409

410-
let _: (Int, Color) = [1,2].map({ ($0, .Unknown("")) }) // expected-error {{cannot convert value of type 'Array<(Int, _)>' to specified type '(Int, Color)'}}
411-
// expected-error@-1 {{cannot infer contextual base in reference to member 'Unknown'}}
410+
let _: (Int, Color) = [1,2].map({ ($0, .Unknown("")) })
411+
// expected-error@-1 {{no 'map' candidates produce the expected contextual result type '(Int, Color)'}}
412+
// expected-note@-2 {{found candidate with type '((Int) throws -> (Int, _)) throws -> Array<(Int, _)>'}}
412413

413414
let _: [(Int, Color)] = [1,2].map({ ($0, .Unknown("")) })// expected-error {{missing argument label 'description:' in call}}
414415

@@ -1248,10 +1249,9 @@ func f11(_ n: Int) {}
12481249
func f11<T : P2>(_ n: T, _ f: @escaping (T) -> T) {} // expected-note {{where 'T' = 'Int'}}
12491250
f11(3, f4) // expected-error {{global function 'f11' requires that 'Int' conform to 'P2'}}
12501251

1251-
// FIXME: Arguably we should also prefer the conformance failure in this case.
1252-
let f12: (Int) -> Void = { _ in }
1253-
func f12<T : P2>(_ n: T, _ f: @escaping (T) -> T) {}
1254-
f12(3, f4)// expected-error {{extra argument in call}}
1252+
let f12: (Int) -> Void = { _ in } // expected-note {{candidate '(Int) -> Void' requires 1 argument, but 2 were provided}}
1253+
func f12<T : P2>(_ n: T, _ f: @escaping (T) -> T) {} // expected-note {{candidate requires that 'Int' conform to 'P2' (requirement specified as 'T' == 'P2')}}
1254+
f12(3, f4)// expected-error {{no exact matches in call to global function 'f12'}}
12551255

12561256
// SR-12242
12571257
struct SR_12242_R<Value> {}

test/Constraints/dynamic_lookup.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func testOverloadedWithUnavailable(ao: AnyObject) {
338338

339339
func dynamicInitCrash(ao: AnyObject.Type) {
340340
let sdk = ao.init(blahblah: ())
341-
// expected-error@-1 {{incorrect argument label in call (have 'blahblah:', expected 'toMemory:')}}
341+
// expected-error@-1 {{no exact matches in call to initializer}}
342342
}
343343

344344
// Test that we correctly diagnose ambiguity for different typed members available

test/Constraints/fixes.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,6 @@ func testKeyPathSubscriptArgFixes(_ fn: @escaping () -> Int) {
358358
}
359359

360360
func sr12426(a: Any, _ str: String?) {
361-
a == str // expected-error {{cannot convert value of type 'Any' to expected argument type 'String'}}
362-
// expected-error@-1 {{value of optional type 'String?' must be unwrapped to a value of type 'String'}}
363-
// expected-note@-2 {{coalesce using '??' to provide a default when the optional value contains 'nil'}}
364-
// expected-note@-3 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
361+
a == str // expected-error {{binary operator '==' cannot be applied to operands of type 'Any' and 'String?'}}
362+
// expected-note@-1 {{overloads for '==' exist with these partially matching parameter lists: (String, String)}}
365363
}

test/Constraints/function.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ func test() {
6262

6363
// <rdar://problem/19962010> QoI: argument label mismatches produce not-great diagnostic
6464
class A {
65-
func a(_ text:String) {
65+
func a(_ text:String) { // expected-note {{incorrect labels for candidate (have: '(text:)', expected: '(_:)')}}
6666
}
67-
func a(_ text:String, something:Int?=nil) {
67+
func a(_ text:String, something:Int?=nil) { // expected-note {{incorrect labels for candidate (have: '(text:)', expected: '(_:)')}}
6868
}
6969
}
70-
A().a(text:"sometext") // expected-error{{extraneous argument label 'text:' in call}}{{7-12=}}
70+
A().a(text:"sometext") // expected-error{{no exact matches in call to instance method 'a'}}
7171

7272

7373
// <rdar://problem/22451001> QoI: incorrect diagnostic when argument to print has the wrong type

test/Constraints/rdar42678836.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-typecheck-verify-swift
22

33
func foo(chr: Character) -> String {
4-
return String(repeating: String(chr)) // expected-error {{missing argument for parameter 'count' in call}} {{39-39=, count: <#Int#>}}
4+
return String(repeating: String(chr)) // expected-error {{no exact matches in call to initializer}}
5+
// expected-note@-1 {{candidate has partially matching parameter list (repeating: String, count: Int)}}
56
}

0 commit comments

Comments
 (0)