Skip to content

[cfe] Parsing e<T1> is T2 #46888

@eernstg

Description

@eernstg

Cf. https://github.com/dart-lang/co19/blob/aff1a334d7875e465c2f43e1b38774512fbb4ba4/LanguageFeatures/Constructor-tear-offs/named_constructor_A02_t02.dart, the CFE parser reports several errors when it encounters an explicit tearoff followed by is:

tests/co19/src/LanguageFeatures/Constructor-tear-offs/named_constructor_A02_t02.dart:27:31: Error: A comparison expression can't be an operand of another comparison expression.
Try putting parentheses around one of the comparisons.
  Expect.isTrue((C.constr)<int> is C Function<T extends int>(T));
                              ^
tests/co19/src/LanguageFeatures/Constructor-tear-offs/named_constructor_A02_t02.dart:27:33: Error: Expected an identifier, but got 'is'.
Try inserting an identifier before 'is'.
  Expect.isTrue((C.constr)<int> is C Function<T extends int>(T));
                                ^^
tests/co19/src/LanguageFeatures/Constructor-tear-offs/named_constructor_A02_t02.dart:27:27: Error: The operator '<' isn't defined for the class 'C<T> Function<T>(T)'.
 - 'C' is from 'tests/co19/src/LanguageFeatures/Constructor-tear-offs/named_constructor_A02_t02.dart'.
Try correcting the operator to an existing operator, or defining a '<' operator.
  Expect.isTrue((C.constr)<int> is C Function<T extends int>(T));
                          ^

However, I believe that there is no way a syntactically correct program could have the token > followed by is unless that > is the end of a <typeArguments> term, and I believe this implies that is can be treated like the disambiguation tokens (( ) ] } : ; , . ? == != .. ?. ?? ?.. & | ^ + * % / ~/), such that the constructs in this test will parse successfully, even though the construct with is isn't ambiguous. So when we see is, we decide that (C.constr)<int> is derived from <primary><selector>.

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onlegacy-area-front-endLegacy: Use area-dart-model instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions