Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Added

- Detailed error message for unsupported casing on Integer.
28 changes: 25 additions & 3 deletions plutus-tx-plugin/src/PlutusTx/Compiler/Type.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
Expand Down Expand Up @@ -355,6 +356,26 @@ stageViolationError tc =
GHC.$+$ ""
GHC.$+$ ghcStrictnessNote

integerCaseError :: GHC.SDoc
integerCaseError =
"Cannot pattern match on a value of type 'Integer'."
GHC.$+$ ""
GHC.$+$ "This usually happens when pattern matching on an integer literal,"
GHC.$+$ "for example:"
GHC.$+$ ""
GHC.$+$ " f 42 = ..."
GHC.$+$ " f n = ..."
GHC.$+$ ""
GHC.$+$ "Plinth does not support pattern matching on 'Integer'. Use equality"
GHC.$+$ "from 'PlutusTx.Prelude' instead, for example:"
GHC.$+$ ""
GHC.$+$ " import PlutusTx.Prelude ((==))"
GHC.$+$ ""
GHC.$+$ " f n | n == 42 = ..."
GHC.$+$ " | otherwise = ..."
GHC.$+$ ""
GHC.$+$ ghcStrictnessNote

-- | Get the constructors of the given 'TyCon' as PLC terms.
getConstructors :: CompilingDefault uni fun m ann => GHC.TyCon -> m [PIRTerm uni fun]
getConstructors tc = do
Expand Down Expand Up @@ -383,9 +404,10 @@ getMatch tc = do
Just match -> pure match
Nothing ->
throwSd UnsupportedError $
if isOpaqueBuiltinTyCon tc
then stageViolationError tc
else "Cannot case on a value on type:" GHC.<+> GHC.ppr tc GHC.$+$ ghcStrictnessNote
if
| tc == GHC.integerTyCon -> integerCaseError
| isOpaqueBuiltinTyCon tc -> stageViolationError tc
| otherwise -> "Cannot case on a value on type:" GHC.<+> GHC.ppr tc GHC.$+$ ghcStrictnessNote

{-| Get the matcher of the given 'Type' (which must be equal to a type constructor application)
as a PLC term instantiated for the type constructor argument types. -}
Expand Down
17 changes: 16 additions & 1 deletion plutus-tx-plugin/test/Plugin/Errors/9.12/caseInt.golden.uplc
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
Error: Unsupported feature: Cannot case on a value on type: GHC.Num.Integer.Integer
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'.
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
Error: Unsupported feature: Cannot case on a value on type: GHC.Num.Integer.Integer
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'.
17 changes: 16 additions & 1 deletion plutus-tx-plugin/test/Plugin/Errors/9.6/caseInt.golden.uplc
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
Error: Unsupported feature: Cannot case on a value on type: GHC.Num.Integer.Integer
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'.
Loading