Sema: Require '.init' when constructing from a dynamic metatype.

This makes it clearer that expressions like "foo.myType.init()" are creating new objects, instead of invoking a weird-looking method. The last part of rdar://problem/21375845.

Swift SVN r29375
This commit is contained in:
Joe Groff
2015-06-14 19:50:06 +00:00
parent 2e8ee5aa4e
commit d7b9ae72aa
30 changed files with 89 additions and 68 deletions

View File

@@ -5521,6 +5521,14 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
// We have a type constructor.
auto metaTy = fn->getType()->castTo<AnyMetatypeType>();
auto ty = metaTy->getInstanceType();
// If the metatype value isn't a type expression, the user should reference
// '.init' explicitly, for clarity.
if (!fn->isTypeReference()) {
cs.TC.diagnose(apply->getArg()->getStartLoc(),
diag::missing_init_on_metatype_initialization)
.fixItInsert(apply->getArg()->getStartLoc(), ".init");
}
// If we're "constructing" a tuple type, it's simply a conversion.
if (auto tupleTy = ty->getAs<TupleType>()) {