Skip to content

c2hs produces crashing Enum instances for any non-contiguous enum #78

Closed
@merijn

Description

@merijn

The enum instances generated by c2hs only define "toEnum :: Enum a => Int -> a" and "fromEnum :: Enum a => a -> Int", relying on the built-in definitions of succ, pred and enumFromTo, however all these built-in functions assume that an Enum matches a contiguous range of Int.

C enums on the other hand don't have this requirement. As a result the generated instance will crash for the Enum instances generated for any such enum. Simple example:

enum HaskellCrasher {
Foo = 1,
Bar = 3,
Baz = 5
};

Trying to call "toEnum 2", will crash. As a result, so will "enumFromTo Foo Baz".

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions