@@ -742,6 +742,130 @@ llvm::DenseMap<Expr *, Expr *> Expr::getParentMap() {
742
742
return parentMap;
743
743
}
744
744
745
+ bool Expr::isValidTypeExprParent () const {
746
+ // Allow references to types as a part of:
747
+ // - member references T.foo, T.Type, T.self, etc.
748
+ // - constructor calls T()
749
+ // - Subscripts T[]
750
+ //
751
+ // This is an exhaustive list of the accepted syntactic forms.
752
+ switch (getKind ()) {
753
+ case ExprKind::Error:
754
+ case ExprKind::DotSelf:
755
+ case ExprKind::Call:
756
+ case ExprKind::MemberRef:
757
+ case ExprKind::UnresolvedMember:
758
+ case ExprKind::DotSyntaxCall:
759
+ case ExprKind::ConstructorRefCall:
760
+ case ExprKind::UnresolvedDot:
761
+ case ExprKind::DotSyntaxBaseIgnored:
762
+ case ExprKind::UnresolvedSpecialize:
763
+ case ExprKind::OpenExistential:
764
+ case ExprKind::Subscript:
765
+ return true ;
766
+
767
+ case ExprKind::NilLiteral:
768
+ case ExprKind::BooleanLiteral:
769
+ case ExprKind::IntegerLiteral:
770
+ case ExprKind::FloatLiteral:
771
+ case ExprKind::StringLiteral:
772
+ case ExprKind::MagicIdentifierLiteral:
773
+ case ExprKind::InterpolatedStringLiteral:
774
+ case ExprKind::ObjectLiteral:
775
+ case ExprKind::DiscardAssignment:
776
+ case ExprKind::DeclRef:
777
+ case ExprKind::SuperRef:
778
+ case ExprKind::Type:
779
+ case ExprKind::OtherConstructorDeclRef:
780
+ case ExprKind::OverloadedDeclRef:
781
+ case ExprKind::UnresolvedDeclRef:
782
+ case ExprKind::DynamicMemberRef:
783
+ case ExprKind::DynamicSubscript:
784
+ case ExprKind::Sequence:
785
+ case ExprKind::Paren:
786
+ case ExprKind::Await:
787
+ case ExprKind::UnresolvedMemberChainResult:
788
+ case ExprKind::Try:
789
+ case ExprKind::ForceTry:
790
+ case ExprKind::OptionalTry:
791
+ case ExprKind::Tuple:
792
+ case ExprKind::Array:
793
+ case ExprKind::Dictionary:
794
+ case ExprKind::KeyPathApplication:
795
+ case ExprKind::TupleElement:
796
+ case ExprKind::CaptureList:
797
+ case ExprKind::Closure:
798
+ case ExprKind::AutoClosure:
799
+ case ExprKind::InOut:
800
+ case ExprKind::VarargExpansion:
801
+ case ExprKind::DynamicType:
802
+ case ExprKind::RebindSelfInConstructor:
803
+ case ExprKind::OpaqueValue:
804
+ case ExprKind::PropertyWrapperValuePlaceholder:
805
+ case ExprKind::AppliedPropertyWrapper:
806
+ case ExprKind::DefaultArgument:
807
+ case ExprKind::BindOptional:
808
+ case ExprKind::OptionalEvaluation:
809
+ case ExprKind::ForceValue:
810
+ case ExprKind::MakeTemporarilyEscapable:
811
+ case ExprKind::PrefixUnary:
812
+ case ExprKind::PostfixUnary:
813
+ case ExprKind::Binary:
814
+ case ExprKind::Load:
815
+ case ExprKind::DestructureTuple:
816
+ case ExprKind::UnresolvedTypeConversion:
817
+ case ExprKind::FunctionConversion:
818
+ case ExprKind::CovariantFunctionConversion:
819
+ case ExprKind::CovariantReturnConversion:
820
+ case ExprKind::ImplicitlyUnwrappedFunctionConversion:
821
+ case ExprKind::MetatypeConversion:
822
+ case ExprKind::CollectionUpcastConversion:
823
+ case ExprKind::Erasure:
824
+ case ExprKind::AnyHashableErasure:
825
+ case ExprKind::BridgeToObjC:
826
+ case ExprKind::BridgeFromObjC:
827
+ case ExprKind::ConditionalBridgeFromObjC:
828
+ case ExprKind::DerivedToBase:
829
+ case ExprKind::ArchetypeToSuper:
830
+ case ExprKind::InjectIntoOptional:
831
+ case ExprKind::ClassMetatypeToObject:
832
+ case ExprKind::ExistentialMetatypeToObject:
833
+ case ExprKind::ProtocolMetatypeToObject:
834
+ case ExprKind::InOutToPointer:
835
+ case ExprKind::ArrayToPointer:
836
+ case ExprKind::StringToPointer:
837
+ case ExprKind::PointerToPointer:
838
+ case ExprKind::ForeignObjectConversion:
839
+ case ExprKind::UnevaluatedInstance:
840
+ case ExprKind::UnderlyingToOpaque:
841
+ case ExprKind::DifferentiableFunction:
842
+ case ExprKind::LinearFunction:
843
+ case ExprKind::DifferentiableFunctionExtractOriginal:
844
+ case ExprKind::LinearFunctionExtractOriginal:
845
+ case ExprKind::LinearToDifferentiableFunction:
846
+ case ExprKind::ForcedCheckedCast:
847
+ case ExprKind::ConditionalCheckedCast:
848
+ case ExprKind::Is:
849
+ case ExprKind::Coerce:
850
+ case ExprKind::Arrow:
851
+ case ExprKind::If:
852
+ case ExprKind::EnumIsCase:
853
+ case ExprKind::Assign:
854
+ case ExprKind::CodeCompletion:
855
+ case ExprKind::UnresolvedPattern:
856
+ case ExprKind::LazyInitializer:
857
+ case ExprKind::EditorPlaceholder:
858
+ case ExprKind::ObjCSelector:
859
+ case ExprKind::KeyPath:
860
+ case ExprKind::KeyPathDot:
861
+ case ExprKind::OneWay:
862
+ case ExprKind::Tap:
863
+ return false ;
864
+ }
865
+
866
+ llvm_unreachable (" Unhandled ExprKind in switch." );
867
+ }
868
+
745
869
// ===----------------------------------------------------------------------===//
746
870
// Support methods for Exprs.
747
871
// ===----------------------------------------------------------------------===//
0 commit comments