Need disambiguation for int literals that can be both native and boxed #8

Closed
moritz opened this Issue Dec 1, 2011 · 1 comment

Comments

Projects
None yet
2 participants
@moritz
Member

moritz commented Dec 1, 2011

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.
@coke

This comment has been minimized.

Show comment
Hide comment
@coke

coke Dec 1, 2011

Contributor

Failures from the current situation visible in t/spec/S03-operators/overflow.t using rakudo/nom on feather.

Contributor

coke commented Dec 1, 2011

Failures from the current situation visible in t/spec/S03-operators/overflow.t using rakudo/nom on feather.

@TimToady TimToady closed this in d519b6f Dec 29, 2013

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