Skip to content

Fix lack of fallback to float for large integer literals#7389

Merged
laurmaedje merged 5 commits intotypst:mainfrom
YDX-2147483647:literal
Nov 21, 2025
Merged

Fix lack of fallback to float for large integer literals#7389
laurmaedje merged 5 commits intotypst:mainfrom
YDX-2147483647:literal

Conversation

@YDX-2147483647
Copy link
Contributor

@YDX-2147483647 YDX-2147483647 commented Nov 16, 2025

Fixes #7388
Relates-to: #5969

@YDX-2147483647 YDX-2147483647 marked this pull request as ready for review November 16, 2025 06:36
@laurmaedje
Copy link
Member

cc @isuffix who had opened #5969

@laurmaedje laurmaedje added syntax About syntax, parsing, etc. fix A bug fix. waiting-on-review This PR is waiting to be reviewed. labels Nov 17, 2025
@laurmaedje
Copy link
Member

I'm wondering whether we actually want to keep this behavior. Perhaps, we should rather turn this into a hard error and require the dot to explicitly turn it into a float.

@laurmaedje laurmaedje added waiting-on-decision A decision must be made to proceed. and removed waiting-on-review This PR is waiting to be reviewed. labels Nov 19, 2025
@YDX-2147483647
Copy link
Contributor Author

Actually, I also find the behaviour weird. There should be a warning at least, like the warning for decimal(1.0).

  • If the typst code is generated by some program, then it's more appropriate to generate json/cbor/... and use data loading functions.
  • If the typst code is written by hand… Oh I can't image how can that be. @kokic, do you have a real use case?
  • Nevertheless, the v0.13.1 behaviour can be retained by #let n = yaml(bytes("9223372036854775808")).

@isuffix
Copy link
Collaborator

isuffix commented Nov 20, 2025

Apologies for the regression! I should've checked the behavior in ast.rs more carefully.

However, I do agree with Laurenz that this is weird. I would consider it an odd piece of trivia if #type(1000000000000000000) differed from #type(10000000000000000000) (there's an extra zero). I don't think erroring on a too-large integer (with hints to either add a dot or use bytes) would be an undue burden.

Another option discussed in #5462 is to just warn on this case, but I don't think changing the type to a float ever really makes sense, so I would prefer an error and require an explicit dot.

Separately, we should just add methods int.min() and int.max() (or maybe int.MIN?) to help with the negative minimum use-case.

@laurmaedje
Copy link
Member

laurmaedje commented Nov 20, 2025

Given the precedent of float.nan, I think it would just be int.min. Uppercase is not really a thing in Typst (which is sometimes annoying because it means variables unnecessarily collide with types ...)

@laurmaedje laurmaedje removed the waiting-on-decision A decision must be made to proceed. label Nov 20, 2025
@laurmaedje
Copy link
Member

Let's turn it into a hard error.

@laurmaedje laurmaedje added the waiting-on-author Pull request waits on author label Nov 20, 2025
@laurmaedje
Copy link
Member

Actually, let's first merge the fix and then introduce the hard error in a separate PR. That way I could cherry-pick should we decide to cut a point release.

@laurmaedje laurmaedje changed the title Fix the parsing of large integer literals Fix lack of fallback to float for large integer literals Nov 21, 2025
@laurmaedje laurmaedje removed the waiting-on-author Pull request waits on author label Nov 21, 2025
@laurmaedje laurmaedje added this pull request to the merge queue Nov 21, 2025
@laurmaedje
Copy link
Member

Thanks! Feel free to open a second PR for introducing a hard error. :)

Merged via the queue into typst:main with commit 630fbbe Nov 21, 2025
8 checks passed
@YDX-2147483647 YDX-2147483647 deleted the literal branch November 21, 2025 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix A bug fix. syntax About syntax, parsing, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integer literals exceeding i64 range are parsed as 0 instead of float

3 participants