Skip to content

Commit bf998e1

Browse files
committed
Clarify parsing ambiguity FIXME comments.
1 parent a319546 commit bf998e1

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,10 +1071,20 @@ static bool parseBaseTypeForQualifiedDeclName(Parser &P, TypeRepr *&baseType) {
10711071
// leading period unparsed to avoid syntax verification errors.
10721072
assert(P.startsWithSymbol(P.Tok, '.') && "false");
10731073

1074-
// Check if this is a reference to an accessor in a computed property.
1075-
// FIXME: There is an ambiguity here because instead of a computed
1076-
// property with an accessor, this could be a type with a function
1077-
// name like an accessor.
1074+
// Check if this is a reference to a property or subscript accessor.
1075+
//
1076+
// Note: There is an parsing ambiguity here. An accessor label identifier
1077+
// (e.g. "set") may refer to the final declaration name component instead of
1078+
// an accessor kind.
1079+
//
1080+
// FIXME: It is wrong to backtrack parsing the entire base type if an accessor
1081+
// label is found. Instead, only the final component of the base type should
1082+
// be backtracked. It may be best to implement this in
1083+
// `Parser::parseTypeIdentifier`.
1084+
//
1085+
// Example: consider parsing `A.B.property.set`.
1086+
// Current behavior: base type is entirely backtracked.
1087+
// Ideal behavior: base type is parsed as `A.B`.
10781088
if (P.Tok.is(tok::period)) {
10791089
const Token &nextToken = P.peekToken();
10801090
if (isAccessorLabel(nextToken).hasValue())
@@ -1123,6 +1133,22 @@ static bool parseQualifiedDeclName(Parser &P, Diag<> nameParseError,
11231133
}
11241134

11251135
// Parse an optional accessor kind.
1136+
//
1137+
// Note: there is an parsing ambiguity here.
1138+
//
1139+
// Example: `A.B.property.set` may be parsed as one of the following:
1140+
//
1141+
// 1. No accessor kind.
1142+
// - Base type: `A.B.property`
1143+
// - Declaration name: `set`
1144+
// - Accessor kind: <none>
1145+
//
1146+
// 2. Accessor kind exists.
1147+
// - Base type: `A.B`
1148+
// - Declaration name: `property`
1149+
// - Accessor kind: `set`
1150+
//
1151+
// Currently, we follow (2) because it's more useful in practice.
11261152
if (P.Tok.is(tok::period)) {
11271153
const Token &nextToken = P.peekToken();
11281154
Optional<AccessorKind> kind = isAccessorLabel(nextToken);

0 commit comments

Comments
 (0)