Skip to content

Add detailed error message for unsupported casing on Integer#7766

Merged
zliu41 merged 2 commits into
masterfrom
zliu41/case-on-integer
May 5, 2026
Merged

Add detailed error message for unsupported casing on Integer#7766
zliu41 merged 2 commits into
masterfrom
zliu41/case-on-integer

Conversation

@zliu41
Copy link
Copy Markdown
Member

@zliu41 zliu41 commented May 4, 2026

Error: Unsupported feature: Cannot pattern match on a value of type 'Integer'.

       This usually happens when pattern matching on an integer literal,
       for example:

         f 42 = ...
         f n  = ...

       Plinth does not support pattern matching on 'Integer'. Use equality
       from 'PlutusTx.Prelude' instead, for example:

         import PlutusTx.Prelude ((==))

         f n | n == 42   = ...
             | otherwise = ...

       Note: GHC can generate these unexpectedly, you may need '-fno-strictness', '-fno-specialise', '-fno-spec-constr', '-fno-unbox-strict-fields', or '-fno-unbox-small-strict-fields'.
   |ᴾᴸᴵᴺᵀᴴ
27 |      let y = PlutusTx.divideInteger 42 (f x)

@zliu41 zliu41 requested review from a team and SeungheonOh May 4, 2026 18:26
Copy link
Copy Markdown
Contributor

@Unisay Unisay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice error message!

Its peculiar that with GHC 9.6 we have 1 golden file change (caseInt) and with 9.12 we have two (caseInt, rangeEnumFromThenTo).

It turns out that:

  1. Plugin tries to detect if a symbol has to do with the enumFromTo or other functions from this family:
    https://github.com/IntersectMBO/plutus/blob/master/plutus-tx-plugin/src/PlutusTx/Compiler/Expr.hs#L365
  2. This detection stopped working in GHC 9.12 - I suspect they moved symbols like rangeEnumFromThenTo to another namespace, like GHC.Internal.Enum instead of GHC.Enum.

It would be nice if you can fix this regression in this PR since its touching the corresponding test.

@zliu41
Copy link
Copy Markdown
Member Author

zliu41 commented May 5, 2026

Plugin tries to detect if a symbol has to do with the enumFromTo

This detection stopped working in GHC 9.12

Neither is accurate. enumFromTo is a result of list range syntax [a..b]. I don't think it has anything to do with pattern matching on Integer.

The plugin does try to detect integerEq, which is a result of pattern matching on Integer. But this is fragile, since GHC could easily decide to inline integerEq. This happens in 9.6 as well as 9.12.

@zliu41 zliu41 merged commit c8f962a into master May 5, 2026
9 checks passed
@zliu41 zliu41 deleted the zliu41/case-on-integer branch May 5, 2026 13:27
@Unisay
Copy link
Copy Markdown
Contributor

Unisay commented May 11, 2026

I don't think it has anything to do with pattern matching on Integer.

I think it does: in this PR the golden file rangeEnumFromThenTo.golden.uplc has changed (it contains integer casing error), and it comes from this code:

rangeEnumFromThenTo :: CompiledCode [Integer]
rangeEnumFromThenTo = plinthc [1, 7 .. 50]

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants