File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -441,14 +441,16 @@ static Constraint *determineBestChoicesInContext(
441
441
}
442
442
443
443
double score = 0.0 ;
444
+ unsigned numDefaulted = 0 ;
444
445
for (unsigned paramIdx = 0 , n = overloadType->getNumParams ();
445
446
paramIdx != n; ++paramIdx) {
446
447
const auto ¶m = overloadType->getParams ()[paramIdx];
447
448
448
449
auto argIndices = matchings->parameterBindings [paramIdx];
449
450
switch (argIndices.size ()) {
450
451
case 0 :
451
- // Current parameter is defaulted.
452
+ // Current parameter is defaulted, mark and continue.
453
+ ++numDefaulted;
452
454
continue ;
453
455
454
456
case 1 :
@@ -542,9 +544,14 @@ static Constraint *determineBestChoicesInContext(
542
544
score += bestCandidateScore;
543
545
}
544
546
547
+ // An overload whether all of the parameters are defaulted
548
+ // that's called without arguments.
549
+ if (numDefaulted == overloadType->getNumParams ())
550
+ return ;
551
+
545
552
// Average the score to avoid disfavoring disjunctions with fewer
546
553
// parameters.
547
- score /= overloadType->getNumParams ();
554
+ score /= ( overloadType->getNumParams () - numDefaulted );
548
555
549
556
// If one of the result types matches exactly, that's a good
550
557
// indication that overload choice should be favored.
Original file line number Diff line number Diff line change 39
39
}
40
40
}
41
41
42
+ // error: initializer for conditional binding must have Optional type, not 'S'
43
+ do {
44
+ struct S {
45
+ let n : Int
46
+ }
47
+
48
+ func f( _: String , _ p: Bool = false ) -> S ? {
49
+ nil
50
+ }
51
+
52
+ func f( _ x: String ) -> S {
53
+ fatalError ( )
54
+ }
55
+
56
+ func g( _ x: String ) -> Int ? {
57
+ guard let y = f ( x) else {
58
+ return nil
59
+ }
60
+ return y. n
61
+ }
62
+ }
63
+
You can’t perform that action at this time.
0 commit comments