@@ -60,19 +60,30 @@ class BuilderClosureVisitor
60
60
// to get diagnostics if something about this builder call fails,
61
61
// e.g. if there isn't a matching overload for `buildBlock`.
62
62
// But we can only do this if there isn't a type variable in the type.
63
- TypeLoc typeLoc (nullptr ,
64
- builderType->hasTypeVariable () ? Type () : builderType);
63
+ TypeLoc typeLoc;
64
+ if (!builderType->hasTypeVariable ()) {
65
+ typeLoc = TypeLoc (new (ctx) FixedTypeRepr (builderType, loc), builderType);
66
+ }
65
67
66
68
auto typeExpr = new (ctx) TypeExpr (typeLoc);
67
69
if (cs) {
68
70
cs->setType (typeExpr, MetatypeType::get (builderType));
69
71
cs->setType (&typeExpr->getTypeLoc (), builderType);
70
72
}
71
73
74
+ SmallVector<SourceLoc, 4 > argLabelLocs;
75
+ for (auto i : indices (argLabels)) {
76
+ argLabelLocs.push_back (args[i]->getStartLoc ());
77
+ }
78
+
72
79
typeExpr->setImplicit ();
73
80
auto memberRef = new (ctx) UnresolvedDotExpr (
74
81
typeExpr, loc, fnName, DeclNameLoc (loc), /* implicit=*/ true );
75
- return CallExpr::createImplicit (ctx, memberRef, args, argLabels);
82
+ SourceLoc openLoc = args.empty () ? loc : args.front ()->getStartLoc ();
83
+ SourceLoc closeLoc = args.empty () ? loc : args.back ()->getEndLoc ();
84
+ return CallExpr::create (ctx, memberRef, openLoc, args,
85
+ argLabels, argLabelLocs, closeLoc,
86
+ /* trailing closure*/ nullptr , /* implicit*/ true );
76
87
}
77
88
78
89
// / Check whether the builder supports the given operation.
@@ -400,18 +411,21 @@ class BuilderClosureVisitor
400
411
auto optionalDecl = ctx.getOptionalDecl ();
401
412
auto optionalType = optionalDecl->getDeclaredType ();
402
413
403
- auto optionalTypeExpr = TypeExpr::createImplicit (optionalType, ctx);
414
+ auto loc = arg->getStartLoc ();
415
+ auto optionalTypeExpr =
416
+ TypeExpr::createImplicitHack (loc, optionalType, ctx);
404
417
auto someRef = new (ctx) UnresolvedDotExpr (
405
- optionalTypeExpr, SourceLoc () , ctx.getIdentifier (" some" ),
406
- DeclNameLoc (), /* implicit=*/ true );
418
+ optionalTypeExpr, loc , ctx.getIdentifier (" some" ),
419
+ DeclNameLoc (loc ), /* implicit=*/ true );
407
420
return CallExpr::createImplicit (ctx, someRef, arg, { });
408
421
}
409
422
410
423
Expr *buildNoneExpr (SourceLoc endLoc) {
411
424
auto optionalDecl = ctx.getOptionalDecl ();
412
425
auto optionalType = optionalDecl->getDeclaredType ();
413
426
414
- auto optionalTypeExpr = TypeExpr::createImplicit (optionalType, ctx);
427
+ auto optionalTypeExpr =
428
+ TypeExpr::createImplicitHack (endLoc, optionalType, ctx);
415
429
return new (ctx) UnresolvedDotExpr (
416
430
optionalTypeExpr, endLoc, ctx.getIdentifier (" none" ),
417
431
DeclNameLoc (endLoc), /* implicit=*/ true );
@@ -492,7 +506,9 @@ TypeChecker::applyFunctionBuilderBodyTransform(FuncDecl *FD,
492
506
if (!returnType || returnType->hasError ())
493
507
return nullptr ;
494
508
495
- auto returnStmt = new (Context) ReturnStmt (SourceLoc (), returnExpr);
509
+ auto loc = returnExpr->getStartLoc ();
510
+ auto returnStmt =
511
+ new (Context) ReturnStmt (loc, returnExpr, /* implicit*/ true );
496
512
return BraceStmt::create (Context, body->getLBraceLoc (), { returnStmt },
497
513
body->getRBraceLoc ());
498
514
}
0 commit comments