Skip to content

Tuple indexing should handle float tokens specially #28257

Closed
@chris-morgan

Description

@chris-morgan

tuple.0.0 tokenises as [Ident("tuple"), Dot, Float("0.0")]. At present it produces an “unexpected token” error with a help message along the lines of “try parenthesizing the first index; e.g., (tuple.0).0”.

This is silly. We should just special-case float literals of the form /\d+.\d+/ and understand them sensibly—that the original one be treated as [Ident("tuple"), Dot, Int("0"), Dot, Int("0")]. It’s not as though there’s any ambiguity (that I see, anyway), and it’s much nicer to handle something automatically where there is no ambiguity and the meaning is perfectly clear, rather than producing a helpful error message.

There’s precedent for this approach to things in the handling of the && token, where the expression &&foo and the pattern &&foo are both treated as two & tokens rather than as a single && token.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions