perl6/specs — Issue #8: Need disambiguation for int literals that can be both native and boxed
Author: moritz
Created: 2011-12-01 14:17:11+00:00
State: open

Nom currently has a problem which IMHO is in big parts a spec issue. Here it comes.

Since no separate literals for native types are specced, a literal like `123` in is polymorphic in rakudo, and can be used both as `Int` or `int`, depending on compile-time context.

Unfortunately that means that an expression like `0x7FFFFFFF * 0x7FFFFFFF` will overflow on a machine with 32 bit ints, because the compiler picks the `infix:<*>(int, int)` candidates, which overflows (as it is allowed to).

I can see several possible solutions:

* spec some separate way to write int vs. Int literals
* assume that literals are always `Int`, and only allow coercion when assigning to an `int`-typed variable (but would make things like `my int $x = 2; $x * 5` less efficient)
* require constant folding in `Int` space when operators only operate on literals, and only make the result of the constant folding polymorphic
* allow the overflow, even if it's suprising to the user.