You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Start using contextual information from function calls to diagnose issues in their
argument. For now we start with some of the most simple cases: single argument
calls. This dramatically improves the QoI for error messages in argument lists,
typically turning a error+note combo into a single specific error message.
Some minor improvements coming (and also generalizing this to n-ary calls), but it
is nice that all the infrastructure is starting to come together...
Swift SVN r30905
makeSureAnyObject(c) // expected-error {{cannot invoke 'makeSureAnyObject' with an argument list of type '(__PrivInt)'}} expected-note {{expected an argument list of type '(AnyObject)'}}
113
+
makeSureAnyObject(c) // expected-error {{type '__PrivInt' (aka 'Int32') does not conform to protocol 'AnyObject'}}
letfridge=CCRefrigeratorCreate(power) // expected-error {{cannot invoke 'CCRefrigeratorCreate' with an argument list of type '(Unmanaged<CCPowerSupplyRef>)'}} expected-note{{expected an argument list of type '(CCPowerSupply!)'}}
16
+
letfridge=CCRefrigeratorCreate(power) // expected-error {{cannot convert value of type 'Unmanaged<CCPowerSupplyRef>' (aka 'Unmanaged<CCPowerSupply>') to expected argument type 'CCPowerSupply!'}}
CCRefrigeratorCreateIndirect(fridge) // expected-error {{cannot invoke 'CCRefrigeratorCreateIndirect' with an argument list of type '(CCRefrigerator?)'}}
115
-
// expected-note @-1 {{expected an argument list of type '(UnsafeMutablePointer<CCRefrigerator?>)'}}
114
+
CCRefrigeratorCreateIndirect(fridge) // expected-error {{cannot convert value of type 'CCRefrigerator?' to expected argument type 'UnsafeMutablePointer<CCRefrigerator?>' (aka 'UnsafeMutablePointer<Optional<CCRefrigerator>>')}}
116
115
117
116
letpower:CCPowerSupply?
118
117
CCRefrigeratorGetPowerSupplyIndirect(0, power) // expected-error {{cannot invoke 'CCRefrigeratorGetPowerSupplyIndirect' with an argument list of type '(Int, CCPowerSupply?)'}}
CCRefrigeratorOpenDoSomething(nil) // expected-error{{cannot invoke 'CCRefrigeratorOpenDoSomething' with an argument list of type '(NilLiteralConvertible)'}}
49
-
// expected-note@-1{{expected an argument list of type '(CCRefrigerator)'}}
48
+
CCRefrigeratorOpenDoSomething(nil) // expected-error{{nil cannot be used in context expecting type 'CCRefrigerator'}}
Copy file name to clipboardExpand all lines: test/ClangModules/objc_parse.swift
+2-4
Original file line number
Diff line number
Diff line change
@@ -50,8 +50,7 @@ func instanceMethods(b: B) {
50
50
// Both class and instance methods exist.
51
51
b.description
52
52
b.instanceTakesObjectClassTakesFloat(b)
53
-
b.instanceTakesObjectClassTakesFloat(2.0) // expected-error{{cannot invoke 'instanceTakesObjectClassTakesFloat' with an argument list of type '(Double)'}}
54
-
// expected-note @-1 {{expected an argument list of type '(AnyObject!)'}}
53
+
b.instanceTakesObjectClassTakesFloat(2.0) // expected-error{{cannot convert value of type 'Double' to expected argument type 'AnyObject!'}}
B.instanceTakesObjectClassTakesFloat(other) // expected-error{{cannot invoke 'instanceTakesObjectClassTakesFloat' with an argument list of type '(NSObject)'}}
75
-
// expected-note @-1 {{expected an argument list of type '(Float)'}}
73
+
B.instanceTakesObjectClassTakesFloat(other) // expected-error{{cannot convert value of type 'NSObject' to expected argument type 'Float'}}
takesProtocol(NonObjCProto.self) // expected-error{{cannot invoke 'takesProtocol' with an argument list of type '(NonObjCProto.Protocol)'}} expected-note{{expected an argument list of type '(Protocol)'}}
17
-
takesProtocol(TwoObjCProtos.self) // expected-error{{cannot invoke 'takesProtocol' with an argument list of type '(TwoObjCProtos.Protocol)'}} expected-note {{expected an argument list of type '(Protocol)'}}
16
+
takesProtocol(NonObjCProto.self) // expected-error{{cannot convert value of type 'NonObjCProto.Protocol' to expectedargument type 'Protocol'}}
17
+
takesProtocol(TwoObjCProtos.self) // expected-error{{cannot convert value of type 'TwoObjCProtos.Protocol' (aka 'protocol<ObjCProto, ObjCProto2>.Protocol') to expected argument type 'Protocol'}}
useIntList([1.0,2,3]) // expected-error{{cannot invoke 'useIntList' with an argument list of type '([Double])'}} expected-note{{expected an argument list of type '(IntList)'}}
46
+
useIntList([1.0,2,3]) // expected-error{{cannot convert value of type '[Double]' to expectedargument type 'IntList'}}
47
47
useDoubleList([1.0,2,3])
48
48
useDoubleList([1.0,2.0,3.0])
49
49
50
50
useIntDict(["Niners"=>31,"Ravens"=>34])
51
-
useIntDict(["Niners"=>31,"Ravens"=>34.0]) // expected-error{{cannot invoke 'useIntDict' with an argument list of type '([(String, Double)])'}} expected-note{{expected an argument list of type '(IntDict)'}}
51
+
useIntDict(["Niners"=>31,"Ravens"=>34.0]) // expected-error{{cannot convert value of type '[(String, Double)]' to expectedargument type 'IntDict'}}
Copy file name to clipboardExpand all lines: test/Constraints/diagnostics.swift
+26-46
Original file line number
Diff line number
Diff line change
@@ -37,8 +37,8 @@ var d : Double
37
37
// Check the various forms of diagnostics the type checker can emit.
38
38
39
39
// Tuple size mismatch.
40
-
f1( // expected-error {{cannot invoke 'f1' with an argument list of type '((Int) -> Int)'}}
41
-
f4 // expected-note @-1 {{expected an argument list of type '((Int, Float) -> Int)'}}
40
+
f1(
41
+
f4 // expected-error {{cannot convert value of type '(Int) -> Int' to expected argument type '(Int, Float) -> Int'}}
42
42
)
43
43
44
44
// Tuple element unused.
@@ -56,12 +56,12 @@ f0(i, // expected-error {{cannot invoke 'f0' with an argument list of type '(Int
56
56
)
57
57
58
58
// Function result not a subtype.
59
-
f1( // expected-error {{cannot invoke 'f1' with an argument list of type '((Int, Float) -> ())'}}
60
-
f0 // expected-note @-1 {{expected an argument list of type '((Int, Float) -> Int)'}}
59
+
f1(
60
+
f0 // expected-error {{cannot convert value of type '(Int, Float) -> ()' to expected argument type '(Int, Float) -> Int'}}
61
61
)
62
62
63
-
f3( // expected-error {{cannot invoke 'f3' with an argument list of type '((((Int) -> Int)) -> Int)'}}
64
-
f2 // expected-note @-1 {{expected an argument list of type '(((Int) -> Float) -> Int)'}}
63
+
f3(
64
+
f2 // expected-error {{cannot convert value of type '(((Int) -> Int)) -> Int' to expected argument type '((Int) -> Float) -> Int'}}
65
65
)
66
66
67
67
// FIXME: Can't test same-type diagnostic yet.
@@ -83,10 +83,8 @@ i.wobble() // expected-error{{value of type 'Int' has no member 'wobble'}}
83
83
// Make sure we don't leave open existentials when diagnosing.
84
84
// <rdar://problem/20598568>
85
85
func pancakes(p:P2){
86
-
f4(p.wonka) // expected-error{{cannot invoke 'f4' with an argument list of type '(() -> ())'}}
87
-
// expected-note@-1{{expected an argument list of type '(Int)'}}
88
-
f4(p.wonka()) // expected-error{{cannot invoke 'f4' with an argument list of type '()'}}
89
-
// expected-note@-1{{expected an argument list of type '(Int)'}}
86
+
f4(p.wonka) // expected-error{{cannot convert value of type '() -> ()' to expected argument type 'Int'}}
87
+
f4(p.wonka()) // expected-error{{cannot convert value of type '()' to expected argument type 'Int'}}
90
88
}
91
89
92
90
protocolShoes{
@@ -263,7 +261,7 @@ _ = 4(1) // expected-error {{cannot call value of non-function type 'Int'}}
263
261
// <rdar://problem/21784170> Incongruous `unexpected trailing closure` error in `init` function which is cast and called without trailing closure.
264
262
func rdar21784170(){
265
263
letinitial=(1.0asDouble,2.0asDouble)
266
-
(Array.init as(Double...)->Array<Double>)(initial as(Double,Double)) // expected-error {{cannot invoke value of type '(Double...) -> Array<Double>' with argument list '(Double, Double)'}}
264
+
(Array.init as(Double...)->Array<Double>)(initial as(Double,Double)) // expected-error {{cannot invoke value of type '(Double...) -> Array<Double>' with argument list '(Double...)'}}
useDictStringInt(["Hello":1,"World":2.5]) // expected-error{{cannot invoke 'useDictStringInt' with an argument list of type '(Dictionary<String, Double>)'}} expected-note{{expected an argument list of type '(DictStringInt)'}}
21
+
useDictStringInt(["Hello":1,"World":2.5]) // expected-error{{cannot convert value of type 'Dictionary<String, Double>' to expectedargument type 'DictStringInt'}}
22
22
useDictStringInt([7:1,"World":2]) // expected-error{{type 'Int2048' does not conform to protocol 'IntegerLiteralConvertible'}}
0 commit comments