Skip to content

Improper Handling of Keyword Escaped Identifiers #808

Description

@InsertCreativityHere

Slice allows you to use keywords as an identifier provided you escape them:

module \int32

However, the way that we handle them under the hood is incorrect and buggy.
This is because right now the \ backslash only exists at lexing time: when the lexer sees an identifier, normally it first performs a lookup against a list of keywords, and only if there is no match do we skip. Either way, the lexer eats the \, and from then on int32 is indistinguishable from the keyword name.


Proposed fix:

We should keep the backslash around as part of the identifier, so that \int32 and int32 can be distinguished not just by the lexer, but by the redefinition checker, the type-patcher, etc.

For correctness' sake though, we should still eat the \ in cases where it's non-useful. For example, it's valid to escape something that isn't a keyword (with the rationale being consistency and because keywords may be added/removed in the future). But, it's important to remove \ in these cases because:

"\Foo" and "Foo" => there should be no difference between these identifiers
"\bool" and "bool" => there should be a difference between these identifiers

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

slicecRelated to the 'slicec' crate

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions