Skip to content

bug: int arithmetic capped at int64 despite arbitrary precision storage #917

@SchoolyB

Description

@SchoolyB

Summary

The int type can store arbitrary precision values (backed by big.Int), but arithmetic operations incorrectly check against int64 bounds and fail with overflow errors.

Steps to Reproduce

Storage works (arbitrary precision):

import @std
using std

do main() {
    temp big int = 999999999999999999999999999999999999999999999999999999999999
    println("Big: ${big}")  // Works!
}

Arithmetic fails (int64 cap):

import @std
using std

do main() {
    temp a int = 999999999999999999999999999999
    temp b int = a + a  // ERROR: exceeds int64 range
}
error[E5005]: integer overflow: 999999999999999999999999999999 + 999999999999999999999999999999 exceeds int64 range

Even simple operations fail:

temp x int = 999999999999999999999999999999 + 1  // ERROR

Expected Behavior

Since int uses big.Int internally, all arithmetic operations should also use arbitrary precision:

temp a int = 999999999999999999999999999999
temp b int = a + a  // Should work: 1999999999999999999999999999998
temp c int = a * a  // Should work: massive number

Affected Operations

  • Addition (+)
  • Multiplication (*)
  • Likely subtraction and others too

Root Cause

The evaluator is likely converting big.Int to int64 before performing arithmetic operations, then checking for overflow. The fix should use big.Int methods directly (Add, Mul, etc.) without int64 conversion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinginterpreterRelated to evaluation and runtime execution

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions