@@ -5035,6 +5035,10 @@ class KeyPathExpr : public Expr {
50355035 // The processed/resolved type, like Foo.Bar in \Foo.Bar.?.baz.
50365036 TypeRepr *RootType = nullptr ;
50375037
5038+ // / Determines whether a key path starts with '.' which denotes necessity for
5039+ // / a contextual root type.
5040+ bool HasLeadingDot = false ;
5041+
50385042public:
50395043 // / A single stored component, which will be one of:
50405044 // / - an unresolved DeclNameRef, which has to be type-checked
@@ -5396,10 +5400,11 @@ class KeyPathExpr : public Expr {
53965400 bool isImplicit = false );
53975401
53985402 KeyPathExpr (SourceLoc backslashLoc, Expr *parsedRoot, Expr *parsedPath,
5399- bool isImplicit = false )
5403+ bool hasLeadingDot, bool isImplicit = false )
54005404 : Expr(ExprKind::KeyPath, isImplicit), StartLoc(backslashLoc),
54015405 EndLoc (parsedPath ? parsedPath->getEndLoc () : parsedRoot->getEndLoc()),
5402- ParsedRoot(parsedRoot), ParsedPath(parsedPath) {
5406+ ParsedRoot(parsedRoot), ParsedPath(parsedPath),
5407+ HasLeadingDot(hasLeadingDot) {
54035408 assert ((parsedRoot || parsedPath) &&
54045409 " keypath must have either root or path" );
54055410 Bits.KeyPathExpr .IsObjC = false ;
@@ -5463,6 +5468,9 @@ class KeyPathExpr : public Expr {
54635468 // / True if this is an ObjC key path expression.
54645469 bool isObjC () const { return Bits.KeyPathExpr .IsObjC ; }
54655470
5471+ // / True if this key path expression has a leading dot.
5472+ bool expectsContextualRoot () const { return HasLeadingDot; }
5473+
54665474 static bool classof (const Expr *E) {
54675475 return E->getKind () == ExprKind::KeyPath;
54685476 }
0 commit comments