c++ ERROR(existential_requires_any,none, "use of %select{protocol |}2%0 as a type must be written %1", (Type, Type, bool))
https://github.com/apple/swift/blob/main/include/swift/AST/DiagnosticsSema.def#L5159-L5161c++ std::string fix; llvm::raw_string_ostream OS(fix); if (needsParens) OS << "("; ExistentialTypeRepr existential(SourceLoc(), replaceRepr); existential.print(OS); if (needsParens) OS << ")"; if (auto *proto = dyn_cast_or_null<ProtocolDecl>(T->getBoundDecl())) { if (proto->existentialRequiresAny() && !Ctx.LangOpts.hasFeature(Feature::ImplicitSome)) { Ctx.Diags.diagnose(T->getNameLoc(), diag::existential_requires_any, proto->getDeclaredInterfaceType(), proto->getDeclaredExistentialType(), /*isAlias=*/false) .fixItReplace(replaceRepr->getSourceRange(), fix); } }
https://github.com/apple/swift/blob/1b6d160c5ce9b55cf82bd4ee0df51774d0410e03/lib/Sema/TypeCheckType.cpp#L5201 (edited)c++ auto parameterized = ParameterizedProtocolType::get(ctx, protoType, argTys); diags.diagnose(loc, diag::existential_requires_any, parameterized, ExistentialType::get(parameterized), /*isAlias=*/isa<TypeAliasType>(type.getPointer()));
https://github.com/apple/swift/blob/1b6d160c5ce9b55cf82bd4ee0df51774d0410e03/lib/Sema/TypeCheckType.cpp#L778-L785c++ needsParens = existentialNeedsParens(*parentIt);
c++ bool existentialNeedsParens(TypeRepr *parent) { switch (parent->getKind()) { case TypeReprKind::Optional: case TypeReprKind::Protocol: return true; case TypeReprKind::Metatype: case TypeReprKind::Attributed: case TypeReprKind::Error: case TypeReprKind::Function: case TypeReprKind::Ownership: case TypeReprKind::Composition: case TypeReprKind::OpaqueReturn: case TypeReprKind::NamedOpaqueReturn: case TypeReprKind::Existential: case TypeReprKind::SimpleIdent: case TypeReprKind::GenericIdent: case TypeReprKind::Member: case TypeReprKind::Dictionary: case TypeReprKind::ImplicitlyUnwrappedOptional: case TypeReprKind::Tuple: case TypeReprKind::Fixed: case TypeReprKind::Array: case TypeReprKind::SILBox: case TypeReprKind::Isolated: case TypeReprKind::Placeholder: case TypeReprKind::CompileTimeConst: case TypeReprKind::Vararg: case TypeReprKind::Pack: case TypeReprKind::PackExpansion: case TypeReprKind::PackElement: return false; } }
case TypeReprKind::ImplicitlyUnwrappedOptional:
を上にもってくるだけでなんかうまくいったりしねえかなw (edited)case TypeReprKind::Composition:
のパターンもあるけどこれはそう簡単な話かどうか微妙だな