Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of underscores in numeric literals semantic #3314

Merged
merged 1 commit into from
Jun 7, 2023
Merged

Conversation

mkaput
Copy link
Member

@mkaput mkaput commented Jun 6, 2023

See added test cases for failing cases examples.


This change is Reviewable

@mkaput mkaput marked this pull request as ready for review June 6, 2023 13:34
@mkaput mkaput requested a review from orizi June 6, 2023 13:34
Copy link
Member Author

@mkaput mkaput left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 3 files reviewed, all discussions resolved (waiting on @orizi)


crates/cairo-lang-syntax/src/node/ast_ext.rs line 53 at r1 (raw file):

        // Catch an edge case, where literal seems to have a suffix that is valid numeric part
        // according to the radix. Interpret this as an untyped numer.
        // Example: 0x1_f32 is interpreted as 0x1F32 without suffix.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=fd921710d30da70c6fda84e016b2cd0f this matches Rust's behaviour

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all commit messages.
Reviewable status: 0 of 3 files reviewed, 1 unresolved discussion (waiting on @mkaput)

a discussion (no related file):
note that this PR does not fix anything - as _ in the middle of a number are not supported in cairo.
this PR adds them - which we are yet to be sure we should.


Copy link
Member Author

@mkaput mkaput left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 3 files reviewed, 1 unresolved discussion (waiting on @orizi)

a discussion (no related file):

Previously, orizi wrote…

note that this PR does not fix anything - as _ in the middle of a number are not supported in cairo.
this PR adds them - which we are yet to be sure we should.

Hmm, the trick is parser already supports _ (otherwise tests I added would fail) and people were trying to use these. The examples in tests are based on a bug report I got from my user who claimed they saw this being used in the wild (all of this was happening on DMs, so I cannot link references).

So I understand this was just an unexpected feature?


Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 3 files at r1.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @mkaput)


crates/cairo-lang-syntax/src/node/ast_ext.rs line 79 at r1 (raw file):

        }
        Some(ty.into())
    }

delete this as well.

Code quote:

    /// Get suffix from this literal if it has one.
    pub fn suffix(&self, db: &dyn SyntaxGroup) -> Option<SmolStr> {
        let text = self.text(db);
        let (_literal, ty) = text.rsplit_once('_')?;
        if ty.is_empty() {
            return None;
        }
        Some(ty.into())
    }

See added test cases for failing cases examples.

commit-id:8bd1ae1d
Copy link
Member Author

@mkaput mkaput left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @orizi)


crates/cairo-lang-syntax/src/node/ast_ext.rs line 79 at r1 (raw file):

Previously, orizi wrote…

delete this as well.

Done.

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: 0 of 3 files reviewed, all discussions resolved (waiting on @mkaput)

@mkaput mkaput enabled auto-merge June 7, 2023 14:22
@mkaput mkaput added this pull request to the merge queue Jun 7, 2023
Merged via the queue into main with commit dc358d4 Jun 7, 2023
@mkaput mkaput deleted the spr/8bd1ae1d branch June 7, 2023 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants