@@ -4506,22 +4506,27 @@ TypeResolver::resolveIsolatedTypeRepr(IsolatedTypeRepr *repr,
45064506 return ErrorType::get (getASTContext ());
45074507 }
45084508
4509+ // Keep the `type` to be returned, while we unwrap and inspect the inner
4510+ // type for whether it can be isolated on.
45094511 Type type = resolveType (repr->getBase (), options);
4512+ Type unwrappedType = type;
45104513
4511- if (auto ty = dyn_cast<DynamicSelfType>(type)) {
4512- type = ty->getSelfType ();
4514+ // Optional actor types are fine - `nil` represents `nonisolated`.
4515+ auto allowOptional = getASTContext ().LangOpts
4516+ .hasFeature (Feature::OptionalIsolatedParameters);
4517+ if (allowOptional) {
4518+ if (auto wrappedOptionalType = unwrappedType->getOptionalObjectType ()) {
4519+ unwrappedType = wrappedOptionalType;
4520+ }
4521+ }
4522+ if (auto dynamicSelfType = dyn_cast<DynamicSelfType>(unwrappedType)) {
4523+ unwrappedType = dynamicSelfType->getSelfType ();
45134524 }
45144525
45154526 // isolated parameters must be of actor type
4516- if (!type->hasTypeParameter () && !type->isAnyActorType () && !type->hasError ()) {
4517- // Optional actor types are fine - `nil` represents `nonisolated`.
4518- auto wrapped = type->getOptionalObjectType ();
4519- auto allowOptional = getASTContext ().LangOpts
4520- .hasFeature (Feature::OptionalIsolatedParameters);
4521- if (allowOptional && wrapped && wrapped->isAnyActorType ()) {
4522- return type;
4523- }
4524-
4527+ if (!unwrappedType->isTypeParameter () &&
4528+ !unwrappedType->isAnyActorType () &&
4529+ !unwrappedType->hasError ()) {
45254530 diagnoseInvalid (
45264531 repr, repr->getSpecifierLoc (), diag::isolated_parameter_not_actor, type);
45274532 return ErrorType::get (type);
0 commit comments