Skip to content

Commit c8f962a

Browse files
authored
Add detailed error message for unsupported casing on Integer (#7766)
1 parent 9df8821 commit c8f962a

5 files changed

Lines changed: 76 additions & 6 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Added
2+
3+
- Detailed error message for unsupported casing on Integer.

plutus-tx-plugin/src/PlutusTx/Compiler/Type.hs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE FlexibleContexts #-}
2+
{-# LANGUAGE MultiWayIf #-}
23
{-# LANGUAGE OverloadedStrings #-}
34
{-# LANGUAGE TupleSections #-}
45
{-# LANGUAGE TypeApplications #-}
@@ -355,6 +356,26 @@ stageViolationError tc =
355356
GHC.$+$ ""
356357
GHC.$+$ ghcStrictnessNote
357358

359+
integerCaseError :: GHC.SDoc
360+
integerCaseError =
361+
"Cannot pattern match on a value of type 'Integer'."
362+
GHC.$+$ ""
363+
GHC.$+$ "This usually happens when pattern matching on an integer literal,"
364+
GHC.$+$ "for example:"
365+
GHC.$+$ ""
366+
GHC.$+$ " f 42 = ..."
367+
GHC.$+$ " f n = ..."
368+
GHC.$+$ ""
369+
GHC.$+$ "Plinth does not support pattern matching on 'Integer'. Use equality"
370+
GHC.$+$ "from 'PlutusTx.Prelude' instead, for example:"
371+
GHC.$+$ ""
372+
GHC.$+$ " import PlutusTx.Prelude ((==))"
373+
GHC.$+$ ""
374+
GHC.$+$ " f n | n == 42 = ..."
375+
GHC.$+$ " | otherwise = ..."
376+
GHC.$+$ ""
377+
GHC.$+$ ghcStrictnessNote
378+
358379
-- | Get the constructors of the given 'TyCon' as PLC terms.
359380
getConstructors :: CompilingDefault uni fun m ann => GHC.TyCon -> m [PIRTerm uni fun]
360381
getConstructors tc = do
@@ -383,9 +404,10 @@ getMatch tc = do
383404
Just match -> pure match
384405
Nothing ->
385406
throwSd UnsupportedError $
386-
if isOpaqueBuiltinTyCon tc
387-
then stageViolationError tc
388-
else "Cannot case on a value on type:" GHC.<+> GHC.ppr tc GHC.$+$ ghcStrictnessNote
407+
if
408+
| tc == GHC.integerTyCon -> integerCaseError
409+
| isOpaqueBuiltinTyCon tc -> stageViolationError tc
410+
| otherwise -> "Cannot case on a value on type:" GHC.<+> GHC.ppr tc GHC.$+$ ghcStrictnessNote
389411

390412
{-| Get the matcher of the given 'Type' (which must be equal to a type constructor application)
391413
as a PLC term instantiated for the type constructor argument types. -}
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
1-
Error: Unsupported feature: Cannot case on a value on type: GHC.Num.Integer.Integer
1+
Error: Unsupported feature: Cannot pattern match on a value of type 'Integer'.
2+
3+
This usually happens when pattern matching on an integer literal,
4+
for example:
5+
6+
f 42 = ...
7+
f n = ...
8+
9+
Plinth does not support pattern matching on 'Integer'. Use equality
10+
from 'PlutusTx.Prelude' instead, for example:
11+
12+
import PlutusTx.Prelude ((==))
13+
14+
f n | n == 42 = ...
15+
| otherwise = ...
16+
217
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'.
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
1-
Error: Unsupported feature: Cannot case on a value on type: GHC.Num.Integer.Integer
1+
Error: Unsupported feature: Cannot pattern match on a value of type 'Integer'.
2+
3+
This usually happens when pattern matching on an integer literal,
4+
for example:
5+
6+
f 42 = ...
7+
f n = ...
8+
9+
Plinth does not support pattern matching on 'Integer'. Use equality
10+
from 'PlutusTx.Prelude' instead, for example:
11+
12+
import PlutusTx.Prelude ((==))
13+
14+
f n | n == 42 = ...
15+
| otherwise = ...
16+
217
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'.
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
1-
Error: Unsupported feature: Cannot case on a value on type: GHC.Num.Integer.Integer
1+
Error: Unsupported feature: Cannot pattern match on a value of type 'Integer'.
2+
3+
This usually happens when pattern matching on an integer literal,
4+
for example:
5+
6+
f 42 = ...
7+
f n = ...
8+
9+
Plinth does not support pattern matching on 'Integer'. Use equality
10+
from 'PlutusTx.Prelude' instead, for example:
11+
12+
import PlutusTx.Prelude ((==))
13+
14+
f n | n == 42 = ...
15+
| otherwise = ...
16+
217
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'.

0 commit comments

Comments
 (0)