File tree Expand file tree Collapse file tree 6 files changed +27
-10
lines changed Expand file tree Collapse file tree 6 files changed +27
-10
lines changed Original file line number Diff line number Diff line change @@ -619,13 +619,25 @@ class TypeVariableStep final : public BindingStep<TypeVarBindingProducer> {
619
619
// / Check whether attempting type variable binding choices should
620
620
// / be stopped, because optimal solution has already been found.
621
621
bool shouldStopAt (const TypeVariableBinding &choice) const override {
622
+ // Let's always attempt default types inferred from literals in diagnostic
623
+ // mode because that could lead to better diagnostics if the problem is
624
+ // contextual like argument/parameter conversion or collection element
625
+ // mismatch.
626
+ if (CS.shouldAttemptFixes ())
627
+ return false ;
628
+
622
629
// If we were able to solve this without considering
623
630
// default literals, don't bother looking at default literals.
624
631
return AnySolved && choice.hasDefaultedProtocol () &&
625
632
!SawFirstLiteralConstraint;
626
633
}
627
634
628
635
bool shouldStopAfter (const TypeVariableBinding &choice) const override {
636
+ // Let's always attempt additional bindings in diagnostic mode, as that
637
+ // could lead to better diagnostic for e.g trying the unwrapped type.
638
+ if (CS.shouldAttemptFixes ())
639
+ return false ;
640
+
629
641
// If there has been at least one solution so far
630
642
// at a current batch of bindings is done it's a
631
643
// success because each new batch would be less
Original file line number Diff line number Diff line change @@ -273,17 +273,17 @@ func verify_NotAC_to_AC_failure(_ arg: () -> ()) {
273
273
// SR-1069 - Error diagnostic refers to wrong argument
274
274
class SR1069_W < T> {
275
275
func append< Key: AnyObject > ( value: T , forKey key: Key ) where Key: Hashable { }
276
- // expected-note@-1 {{where 'Key' = 'Object?'}}
277
276
}
278
277
class SR1069_C < T> { let w : SR1069_W < ( AnyObject , T ) -> ( ) > = SR1069_W ( ) }
279
278
struct S < T> {
280
279
let cs : [ SR1069_C < T > ] = [ ]
281
280
282
281
func subscribe< Object: AnyObject > ( object: Object ? , method: ( Object , T ) -> ( ) ) where Object: Hashable {
283
282
let wrappedMethod = { ( object: AnyObject , value: T ) in }
284
- // expected-error @+2 {{instance method 'append(value:forKey:)' requires that 'Object?' be a class type}}
285
- // expected-note @+1 {{wrapped type 'Object' satisfies this requirement}}
286
283
cs. forEach { $0. w. append ( value: wrappedMethod, forKey: object) }
284
+ // expected-error@-1 {{value of optional type 'Object?' must be unwrapped to a value of type 'Object'}}
285
+ // expected-note@-2 {{coalesce using '??' to provide a default when the optional value contains 'nil'}}
286
+ // expected-note@-3 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
287
287
}
288
288
}
289
289
Original file line number Diff line number Diff line change @@ -182,6 +182,14 @@ var s1116 = Set(1...10).subtracting(a1116.map({ $0.s })) // expected-error {{val
182
182
// expected-note@-1{{coalesce using '??' to provide a default when the optional value contains 'nil'}} {{49-49=(}} {{53-53= ?? <#default value#>)}}
183
183
// expected-note@-2{{force-unwrap using '!' to abort execution if the optional value contains 'nil'}} {{53-53=!}}
184
184
185
+ func makeArray< T> ( _ x: T ) -> [ T ] { [ x] }
186
+
187
+ func sr12399( _ x: Int ? ) {
188
+ _ = Set ( 0 ... 10 ) . subtracting ( makeArray ( x) ) // expected-error {{value of optional type 'Int?' must be unwrapped to a value of type 'Int'}}
189
+ // expected-note@-1{{coalesce using '??' to provide a default when the optional value contains 'nil'}} {{42-42= ?? <#default value#>}}
190
+ // expected-note@-2{{force-unwrap using '!' to abort execution if the optional value contains 'nil'}} {{42-42=!}}
191
+ }
192
+
185
193
func moreComplexUnwrapFixes( ) {
186
194
struct S {
187
195
let value : Int
Original file line number Diff line number Diff line change @@ -798,19 +798,15 @@ func trailingclosure4(f: () -> Int) {}
798
798
trailingclosure4 { 5 }
799
799
800
800
func trailingClosure5< T> ( _ file: String = #file, line: UInt = #line, expression: ( ) -> T ? ) { }
801
- // expected-note@-1 {{in call to function 'trailingClosure5(_:line:expression:)'}}
802
801
func trailingClosure6< T> ( value: Int , expression: ( ) -> T ? ) { }
803
- // expected-note@-1 {{in call to function 'trailingClosure6(value:expression:)'}}
804
802
805
803
trailingClosure5 ( file: " hello " , line: 17 ) { // expected-error{{extraneous argument label 'file:' in call}}{{18-24=}}
806
- // expected-error@-1 {{generic parameter 'T' could not be inferred}}
807
804
return Optional . Some ( 5 )
808
805
// expected-error@-1 {{enum type 'Optional<Wrapped>' has no case 'Some'; did you mean 'some'?}} {{19-23=some}}
809
806
// expected-error@-2 {{generic parameter 'Wrapped' could not be inferred}}
810
807
// expected-note@-3 {{explicitly specify the generic arguments to fix this issue}}
811
808
}
812
809
trailingClosure6 ( 5 ) { // expected-error{{missing argument label 'value:' in call}}{{18-18=value: }}
813
- // expected-error@-1 {{generic parameter 'T' could not be inferred}}
814
810
return Optional . Some ( 5 )
815
811
// expected-error@-1 {{enum type 'Optional<Wrapped>' has no case 'Some'; did you mean 'some'?}} {{19-23=some}}
816
812
// expected-error@-2 {{generic parameter 'Wrapped' could not be inferred}}
Original file line number Diff line number Diff line change @@ -319,8 +319,9 @@ func foo() {
319
319
let j = min ( Int ( 3 ) , Float ( 2.5 ) ) // expected-error{{conflicting arguments to generic parameter 'T' ('Int' vs. 'Float')}}
320
320
let k = min ( A ( ) , A ( ) ) // expected-error{{global function 'min' requires that 'A' conform to 'Comparable'}}
321
321
let oi : Int ? = 5
322
- let l = min ( 3 , oi) // expected-error{{global function 'min' requires that 'Int?' conform to 'Comparable'}}
323
- // expected-note@-1{{wrapped type 'Int' satisfies this requirement}}
322
+ let l = min ( 3 , oi) // expected-error {{value of optional type 'Int?' must be unwrapped to a value of type 'Int'}}
323
+ // expected-note@-1 {{coalesce using '??' to provide a default when the optional value contains 'nil'}}
324
+ // expected-note@-2 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
324
325
}
325
326
326
327
infix operator +&
Original file line number Diff line number Diff line change @@ -51,4 +51,4 @@ var _: HasClosure = .factoryOpt(3)
51
51
// expected-note@-2 {{coalesce}}
52
52
// expected-note@-3 {{force-unwrap}}
53
53
// FIXME: we should accept this
54
- var _: HasClosure = . factoryOpt!( 4 ) // expected-error {{type 'Optional<_>' has no member 'factoryOpt'}}
54
+ var _: HasClosure = . factoryOpt!( 4 ) // expected-error {{cannot infer contextual base in reference to member 'factoryOpt'}}
You can’t perform that action at this time.
0 commit comments