mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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>()) {
|
||||
|
||||
Reference in New Issue
Block a user