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

Error not raised with max_int+1 integer literal #4689

Closed
vicuna opened this issue Jan 9, 2009 · 3 comments
Closed

Error not raised with max_int+1 integer literal #4689

vicuna opened this issue Jan 9, 2009 · 3 comments

Comments

@vicuna
Copy link

vicuna commented Jan 9, 2009

Original bug ID: 4689
Reporter: llb
Status: resolved (set by @xavierleroy on 2012-08-02T17:25:40Z)
Resolution: suspended
Priority: normal
Severity: minor
Version: 3.11.0+beta
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @glondu

Bug description

max_int;;

  • : int = 1073741823

1073741824;;

  • : int = -1073741824

1073741825;;

Characters 0-10:
1073741825;;
^^^^^^^^^^
Error: Integer literal exceeds the range of representable integers of type int

The integer literal 1073741824 should rise an error, since it's greater than max_int. It currently returns an erroneous value.

@vicuna
Copy link
Author

vicuna commented Jan 9, 2009

Comment author: llb

Oops, sorry, bad title.
Should be "Error not raised with max_int+1 integer literal", or something like that.

@vicuna
Copy link
Author

vicuna commented Jan 14, 2009

Comment author: @damiendoligez

Note: for technical reasons, this is unlikely to be fixed in the near future.

@vicuna
Copy link
Author

vicuna commented Aug 2, 2012

Comment author: @xavierleroy

Let me document the "technical reasons".

1- Because "f-1" should not be parsed as "f(-1)", "-1073741824" is, lexically, the unary minus operator applied to "1073741824". So, we need to be able to represent "1073741824" (the opposite of min_int) in lexer tokens.

2- Still assuming a 32-bit platform, we really want to be able to write
"x land 0x4000_0000" (or similar bit-masking operations) and not be forced to write "x land (-0x4000_0000)".

The problem reported could possibly be solved by keeping integer literals as strings during lexing and parsing, pushing their resolution into integers deeper in the compiler. But that's a lot of changes for a minor benefit. I'm suspending this PR until someone comes up with a better idea.

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

No branches or pull requests

1 participant