@@ -2106,9 +2106,6 @@ namespace {
2106
2106
repr->setInvalid ();
2107
2107
return diags.diagnose (std::forward<ArgTypes>(Args)...);
2108
2108
}
2109
-
2110
- bool diagnoseMoveOnlyGeneric (TypeRepr *repr,
2111
- Type unboundTy, Type genericArgTy);
2112
2109
2113
2110
bool diagnoseDisallowedExistential (TypeRepr *repr);
2114
2111
@@ -2500,33 +2497,6 @@ bool TypeResolver::diagnoseInvalidPlaceHolder(OpaqueReturnTypeRepr *repr) {
2500
2497
return false ;
2501
2498
}
2502
2499
2503
- // / Checks the given type, assuming that it appears as an argument for a
2504
- // / generic parameter in the \c repr, to see if it is move-only.
2505
- // /
2506
- // / Because generic type parameters currently all assume copyability of
2507
- // / the substituted type, it's an error for a move-only type to appear
2508
- // / as an argument for type parameters.
2509
- // /
2510
- // / returns true if an error diagnostic was emitted
2511
- bool TypeResolver::diagnoseMoveOnlyGeneric (TypeRepr *repr,
2512
- Type unboundTy,
2513
- Type genericArgTy) {
2514
- if (getASTContext ().LangOpts .hasFeature (Feature::NoncopyableGenerics))
2515
- return false ;
2516
-
2517
- if (genericArgTy->isNoncopyable ()) {
2518
- if (unboundTy) {
2519
- diagnoseInvalid (repr, repr->getLoc (), diag::noncopyable_generics_specific,
2520
- genericArgTy, unboundTy);
2521
- } else {
2522
- diagnoseInvalid (repr, repr->getLoc (), diag::noncopyable_generics,
2523
- genericArgTy);
2524
- }
2525
- return true ;
2526
- }
2527
- return false ;
2528
- }
2529
-
2530
2500
2531
2501
bool swift::diagnoseMissingOwnership (ParamSpecifier ownership,
2532
2502
TypeRepr *repr, Type ty,
@@ -5011,17 +4981,26 @@ NeverNullType TypeResolver::resolveArrayType(ArrayTypeRepr *repr,
5011
4981
// If the standard library isn't loaded, we ought to let the user know
5012
4982
// something has gone terribly wrong, since the rest of the compiler is going
5013
4983
// to assume it can canonicalize [T] to Array<T>.
5014
- if (!ctx.getArrayDecl ()) {
5015
- ctx.Diags .diagnose (repr->getBrackets ().Start ,
5016
- diag::sugar_type_not_found, 0 );
5017
- return ErrorType::get (ctx);
5018
- }
4984
+ {
4985
+ // Check that we can validly substitute the baseTy into an array. We do not
4986
+ // actually resolve to that valid array type, as we want to return the
4987
+ // sugared Type node ArraySliceType instead!
4988
+ auto *arrayDecl = ctx.getArrayDecl ();
4989
+ if (!arrayDecl) {
4990
+ ctx.Diags .diagnose (repr->getBrackets ().Start ,
4991
+ diag::sugar_type_not_found, 0 );
4992
+ return ErrorType::get (ctx);
4993
+ }
5019
4994
5020
- // do not allow move-only types in an array
5021
- if (diagnoseMoveOnlyGeneric (repr,
5022
- ctx.getArrayDecl ()->getDeclaredInterfaceType (),
5023
- baseTy)) {
5024
- return ErrorType::get (ctx);
4995
+ Type genericArgs[1 ] = {baseTy};
4996
+ auto arrayTy =
4997
+ resolution.applyUnboundGenericArguments (arrayDecl,
4998
+ /* parentTy=*/ nullptr ,
4999
+ repr->getBrackets ().Start ,
5000
+ genericArgs);
5001
+ if (arrayTy->hasError ()) {
5002
+ return ErrorType::get (ctx);
5003
+ }
5025
5004
}
5026
5005
5027
5006
return ArraySliceType::get (baseTy);
@@ -5116,11 +5095,17 @@ NeverNullType TypeResolver::resolveOptionalType(OptionalTypeRepr *repr,
5116
5095
return ErrorType::get (ctx);
5117
5096
}
5118
5097
5119
- // do not allow move-only types in an optional
5120
- if (diagnoseMoveOnlyGeneric (repr,
5121
- ctx.getOptionalDecl ()->getDeclaredInterfaceType (),
5122
- baseTy)) {
5123
- return ErrorType::get (ctx);
5098
+ {
5099
+ // Check that we can validly substitute the baseTy into an Optional
5100
+ Type genericArgs[1 ] = {baseTy};
5101
+ auto substTy =
5102
+ resolution.applyUnboundGenericArguments (ctx.getOptionalDecl (),
5103
+ /* parentTy=*/ nullptr ,
5104
+ repr->getQuestionLoc (),
5105
+ genericArgs);
5106
+ if (substTy->hasError ()) {
5107
+ return ErrorType::get (ctx);
5108
+ }
5124
5109
}
5125
5110
5126
5111
return optionalTy;
@@ -5221,11 +5206,17 @@ NeverNullType TypeResolver::resolveImplicitlyUnwrappedOptionalType(
5221
5206
return ErrorType::get (ctx);
5222
5207
}
5223
5208
5224
- // do not allow move-only types in an implicitly-unwrapped optional
5225
- if (diagnoseMoveOnlyGeneric (repr,
5226
- ctx.getOptionalDecl ()->getDeclaredInterfaceType (),
5227
- baseTy)) {
5228
- return ErrorType::get (ctx);
5209
+ {
5210
+ // Check that we can validly substitute the baseTy into an Optional
5211
+ Type genericArgs[1 ] = {baseTy};
5212
+ auto substTy =
5213
+ resolution.applyUnboundGenericArguments (ctx.getOptionalDecl (),
5214
+ /* parentTy=*/ nullptr ,
5215
+ repr->getExclamationLoc (),
5216
+ genericArgs);
5217
+ if (substTy->hasError ()) {
5218
+ return ErrorType::get (ctx);
5219
+ }
5229
5220
}
5230
5221
5231
5222
return uncheckedOptionalTy;
0 commit comments