|
1 | 1 | {-# LANGUAGE FlexibleContexts #-} |
| 2 | +{-# LANGUAGE MultiWayIf #-} |
2 | 3 | {-# LANGUAGE OverloadedStrings #-} |
3 | 4 | {-# LANGUAGE TupleSections #-} |
4 | 5 | {-# LANGUAGE TypeApplications #-} |
@@ -355,6 +356,26 @@ stageViolationError tc = |
355 | 356 | GHC.$+$ "" |
356 | 357 | GHC.$+$ ghcStrictnessNote |
357 | 358 |
|
| 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 | + |
358 | 379 | -- | Get the constructors of the given 'TyCon' as PLC terms. |
359 | 380 | getConstructors :: CompilingDefault uni fun m ann => GHC.TyCon -> m [PIRTerm uni fun] |
360 | 381 | getConstructors tc = do |
@@ -383,9 +404,10 @@ getMatch tc = do |
383 | 404 | Just match -> pure match |
384 | 405 | Nothing -> |
385 | 406 | 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 |
389 | 411 |
|
390 | 412 | {-| Get the matcher of the given 'Type' (which must be equal to a type constructor application) |
391 | 413 | as a PLC term instantiated for the type constructor argument types. -} |
|
0 commit comments