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