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

'System.OverflowException: Value was either too large or too small for a UInt64' on integer assignment #205

Closed
perlun opened this issue Sep 10, 2021 · 0 comments · Fixed by #215
Labels
bug Something isn't working as expected
Milestone

Comments

@perlun
Copy link
Collaborator

perlun commented Sep 10, 2021

The following program:

var j = 1231231230912839019312831232;

...currently fails with the following exception:

Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.OverflowException: Value was either too large or too small for a UInt64.
   at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
   at System.Number.ParseUInt64(ReadOnlySpan`1 value, NumberStyles styles, NumberFormatInfo info)
   at System.UInt64.Parse(String s)
   at Perlang.Parser.Scanner.Number() in /home/per/git/perlang/src/Perlang.Parser/Scanner.cs:line 327
   at Perlang.Parser.Scanner.ScanToken() in /home/per/git/perlang/src/Perlang.Parser/Scanner.cs:line 265
   at Perlang.Parser.Scanner.ScanTokens() in /home/per/git/perlang/src/Perlang.Parser/Scanner.cs:line 146
   at Perlang.Interpreter.PerlangInterpreter.Eval(String source, ScanErrorHandler scanErrorHandler, ParseErrorHandler parseErrorHandler, ResolveErrorHandler resolveErrorHandler, ValidationErrorHandler typeValidationErrorHandler, ValidationErrorHandler immutabilityValidationErrorHandler, CompilerWarningHandler compilerWarningHandler) in /home/per/git/perlang/src/Perlang.Interpreter/PerlangInterpreter.cs:line 191
   at Perlang.ConsoleApp.Program.Run(String source, CompilerWarningHandler compilerWarningHandler) in /home/per/git/perlang/src/Perlang.ConsoleApp/Program.cs:line 351
   at Perlang.ConsoleApp.Program.RunPrompt() in /home/per/git/perlang/src/Perlang.ConsoleApp/Program.cs:line 345
   at Perlang.ConsoleApp.Program.<>c__DisplayClass9_0.<MainWithCustomConsole>b__3(ParseResult parseResult, IConsole console) in /home/per/git/perlang/src/Perlang.ConsoleApp/Program.cs:line 180

We should handle this more gracefully; for example, in the REPL, this currently kills the execution.

@perlun perlun added the bug Something isn't working as expected label Sep 10, 2021
@perlun perlun added this to the 0.1.0 milestone Sep 10, 2021
@perlun perlun changed the title Avoid OverflowException on integer assignment 'System.OverflowException: Value was either too large or too small for a UInt64' on integer assignment Sep 10, 2021
perlun pushed a commit that referenced this issue Oct 10, 2021
The simple fix for now is to just parse them as `BitInteger`. An
interesting question is if we should support suffixes like L, U, UL etc,
as in C#. I think the simple answer is "we don't know", and we'll wait
with implementing things like that until there's a good-enough
motivation for it.

Closes #205
perlun added a commit that referenced this issue Oct 10, 2021
The simple fix for now is to just parse them as `BitInteger`. An
interesting question is if we should support suffixes like L, U, UL etc,
as in C#. I think the simple answer is "we don't know", and we'll wait
with implementing things like that until there's a good-enough
motivation for it.

Closes #205
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant