@@ -360,7 +360,7 @@ namespace {
360
360
// / expression, attempt to derive a favored type for it.
361
361
bool computeFavoredTypeForExpr (Expr *expr, ConstraintSystem &CS) {
362
362
LinkedTypeInfo lti;
363
-
363
+
364
364
expr->walk (LinkedExprAnalyzer (lti, CS));
365
365
366
366
// Link anonymous closure params of the same index.
@@ -381,41 +381,21 @@ namespace {
381
381
}
382
382
}
383
383
384
- // Link integer literal tyvars.
385
- if (lti.intLiteralTyvars .size () > 1 ) {
386
- auto rep1 = CS.getRepresentative (lti.intLiteralTyvars [0 ]);
387
-
388
- for (size_t i = 1 ; i < lti.intLiteralTyvars .size (); i++) {
389
- auto rep2 = CS.getRepresentative (lti.intLiteralTyvars [i]);
384
+ auto mergeTypeVariables = [&](ArrayRef<TypeVariableType *> typeVars) {
385
+ if (typeVars.size () < 2 )
386
+ return ;
390
387
388
+ auto rep1 = CS.getRepresentative (typeVars.front ());
389
+ for (unsigned i = 1 , n = typeVars.size (); i != n; ++i) {
390
+ auto rep2 = CS.getRepresentative (typeVars[i]);
391
391
if (rep1 != rep2)
392
392
CS.mergeEquivalenceClasses (rep1, rep2, /* updateWorkList*/ false );
393
393
}
394
- }
395
-
396
- // Link float literal tyvars.
397
- if (lti.floatLiteralTyvars .size () > 1 ) {
398
- auto rep1 = CS.getRepresentative (lti.floatLiteralTyvars [0 ]);
399
-
400
- for (size_t i = 1 ; i < lti.floatLiteralTyvars .size (); i++) {
401
- auto rep2 = CS.getRepresentative (lti.floatLiteralTyvars [i]);
402
-
403
- if (rep1 != rep2)
404
- CS.mergeEquivalenceClasses (rep1, rep2, /* updateWorkList*/ false );
405
- }
406
- }
407
-
408
- // Link string literal tyvars.
409
- if (lti.stringLiteralTyvars .size () > 1 ) {
410
- auto rep1 = CS.getRepresentative (lti.stringLiteralTyvars [0 ]);
411
-
412
- for (size_t i = 1 ; i < lti.stringLiteralTyvars .size (); i++) {
413
- auto rep2 = CS.getRepresentative (lti.stringLiteralTyvars [i]);
394
+ };
414
395
415
- if (rep1 != rep2)
416
- CS.mergeEquivalenceClasses (rep1, rep2, /* updateWorkList*/ false );
417
- }
418
- }
396
+ mergeTypeVariables (lti.intLiteralTyvars );
397
+ mergeTypeVariables (lti.floatLiteralTyvars );
398
+ mergeTypeVariables (lti.stringLiteralTyvars );
419
399
420
400
if (lti.collectedTypes .size () == 1 ) {
421
401
// TODO: Compute the BCT.
0 commit comments