@@ -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,
@@ -5014,17 +4984,26 @@ NeverNullType TypeResolver::resolveArrayType(ArrayTypeRepr *repr,
5014
4984
// If the standard library isn't loaded, we ought to let the user know
5015
4985
// something has gone terribly wrong, since the rest of the compiler is going
5016
4986
// to assume it can canonicalize [T] to Array<T>.
5017
- if (!ctx.getArrayDecl ()) {
5018
- ctx.Diags .diagnose (repr->getBrackets ().Start ,
5019
- diag::sugar_type_not_found, 0 );
5020
- return ErrorType::get (ctx);
5021
- }
4987
+ {
4988
+ // Check that we can validly substitute the baseTy into an array. We do not
4989
+ // actually resolve to that valid array type, as we want to return the
4990
+ // sugared Type node ArraySliceType instead!
4991
+ auto *arrayDecl = ctx.getArrayDecl ();
4992
+ if (!arrayDecl) {
4993
+ ctx.Diags .diagnose (repr->getBrackets ().Start ,
4994
+ diag::sugar_type_not_found, 0 );
4995
+ return ErrorType::get (ctx);
4996
+ }
5022
4997
5023
- // do not allow move-only types in an array
5024
- if (diagnoseMoveOnlyGeneric (repr,
5025
- ctx.getArrayDecl ()->getDeclaredInterfaceType (),
5026
- baseTy)) {
5027
- return ErrorType::get (ctx);
4998
+ Type genericArgs[1 ] = {baseTy};
4999
+ auto arrayTy =
5000
+ resolution.applyUnboundGenericArguments (arrayDecl,
5001
+ /* parentTy=*/ nullptr ,
5002
+ repr->getBrackets ().Start ,
5003
+ genericArgs);
5004
+ if (arrayTy->hasError ()) {
5005
+ return ErrorType::get (ctx);
5006
+ }
5028
5007
}
5029
5008
5030
5009
return ArraySliceType::get (baseTy);
@@ -5119,11 +5098,17 @@ NeverNullType TypeResolver::resolveOptionalType(OptionalTypeRepr *repr,
5119
5098
return ErrorType::get (ctx);
5120
5099
}
5121
5100
5122
- // do not allow move-only types in an optional
5123
- if (diagnoseMoveOnlyGeneric (repr,
5124
- ctx.getOptionalDecl ()->getDeclaredInterfaceType (),
5125
- baseTy)) {
5126
- return ErrorType::get (ctx);
5101
+ {
5102
+ // Check that we can validly substitute the baseTy into an Optional
5103
+ Type genericArgs[1 ] = {baseTy};
5104
+ auto substTy =
5105
+ resolution.applyUnboundGenericArguments (ctx.getOptionalDecl (),
5106
+ /* parentTy=*/ nullptr ,
5107
+ repr->getQuestionLoc (),
5108
+ genericArgs);
5109
+ if (substTy->hasError ()) {
5110
+ return ErrorType::get (ctx);
5111
+ }
5127
5112
}
5128
5113
5129
5114
return optionalTy;
@@ -5224,11 +5209,17 @@ NeverNullType TypeResolver::resolveImplicitlyUnwrappedOptionalType(
5224
5209
return ErrorType::get (ctx);
5225
5210
}
5226
5211
5227
- // do not allow move-only types in an implicitly-unwrapped optional
5228
- if (diagnoseMoveOnlyGeneric (repr,
5229
- ctx.getOptionalDecl ()->getDeclaredInterfaceType (),
5230
- baseTy)) {
5231
- return ErrorType::get (ctx);
5212
+ {
5213
+ // Check that we can validly substitute the baseTy into an Optional
5214
+ Type genericArgs[1 ] = {baseTy};
5215
+ auto substTy =
5216
+ resolution.applyUnboundGenericArguments (ctx.getOptionalDecl (),
5217
+ /* parentTy=*/ nullptr ,
5218
+ repr->getExclamationLoc (),
5219
+ genericArgs);
5220
+ if (substTy->hasError ()) {
5221
+ return ErrorType::get (ctx);
5222
+ }
5232
5223
}
5233
5224
5234
5225
return uncheckedOptionalTy;
0 commit comments