Skip to content

Inlining of negate can produce out of bounds Int values #2136

@hdgarrood

Description

@hdgarrood

For example, with prelude v1.0.0-rc.3:

> let x = negate (bottom :: Int)
> x
2147483648

> x > top :: Int
true

I think this is because negate is being inlined without a | 0 for Int values. For example:

module Main where

import Prelude

main = negate (bottom :: Int) > top

produces

var main = -Data_Bounded.bottom(Data_Bounded.boundedInt) > Data_Bounded.top(Data_Bounded.boundedInt);

Adding a bitwise-or with 0 would mean that we would get negate bottom == bottom :: Int instead, which is a bit weird, but at least means that Int is actually a 32-bit integer.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions