Skip to content

[#286] Improve `ArithError` to remove impossible representation

Moremi Vannak requested to merge rinn7e/#286-investigate-overflow-scenarios into master

Description

Problem: We have

-- | Denotes the error type occured in the arithmetic operation.
data ArithErrorType
  = AddOverflow
  | MulOverflow
  | SubUnderflow
  | LslOverflow
  | LsrUnderflow
  deriving stock (Show, Eq, Ord, Generic)

-- | Represents an arithmetic error of the operation.
data ArithError n m
  = MutezArithError ArithErrorType n m
  | ShiftArithError ArithErrorType n m
  deriving stock (Show, Eq, Ord, Generic)

LslOverflow and LsrUnderflow can only happen in ShiftArithError and the other three can only be part of MutezArithError. But it's not reflected in type.

Solution: Turn ArithErrorType into two types: ShiftArithErrorType and MutezArithErrorType.

Related issue(s)

Resolves #286 (closed)

Checklist for your Merge Request

Related changes (conditional)

  • Tests (see short guidelines)

    • If I added new functionality, I added tests covering it.
    • If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
  • Documentation

    • I checked whether I should update the docs and did so if necessary:
    • I updated changelog files of all affected packages released to Hackage if my changes are externally visible.

Stylistic guide (mandatory)

Edited by Moremi Vannak

Merge request reports