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
1 change: 1 addition & 0 deletions plinth/test/cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ index-state:

packages:
./.
./no-pragmas-dep

optional-packages:
../../plutus/plutus-tx
Expand Down
38 changes: 34 additions & 4 deletions plinth/test/errors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,26 @@ ACCEPT=1 ./run-error-tests.sh

# use a different compiler:
GHC=/path/to/plinthc ./run-error-tests.sh

# run one mode only:
MODES=locs ./run-error-tests.sh
```

`plinthc-test.sh` runs this suite automatically.

All cases compile with `preserve-source-locations` enabled, because
the goal of this suite is to track how much source-location
information each error carries.
The suite runs each case in two modes:

- `locs`: with the plugin option `preserve-source-locations`. The
goldens are in `golden/<GHC major.minor>/`. This mode pins how
precise the locations can be.
- `nolocs`: without the option, as in a project that does not set it.
The goldens are in `golden/<GHC major.minor>/nolocs/`. This mode pins
what a user gets by default.

In both modes, the runner also does a check that does not depend on the
goldens: the output of a case must start with a located error header
(`File.hs:l:c: error:`) and must not contain `<no location info>`. A
case without a source location fails, also with `ACCEPT=1`.

## Cases

Expand All @@ -41,8 +54,15 @@ precise it is: "expression" points at the offending expression,
location often means GHC inlined a small same-module function into
the splice before the plugin ran.

The table gives the location in the `locs` mode. In the `nolocs` mode,
these cases point at the definition instead: DeepChain (at `outer`, not
at `inner`), LitChar, LitDouble, LitString, MachineInt, MachineWord,
NoUnfolding and ToBuiltinUsed. The other cases have the same location
in both modes.

| Case | Construct | Location |
|---------------------|------------------------------------|-------------|
| CrossModule | unsupported code in an imported function | expression (in the imported module) |
| DeepChain | error inside nested functions | expression |
| EnumMethod | Prelude Enum method | splice |
| EnumRange | range syntax / enumFromTo | splice |
Expand All @@ -53,6 +73,7 @@ the splice before the plugin ran.
| HaskellShow | Prelude Show method | splice |
| IOAction | IO action | splice |
| IntegerPatternMatch | pattern match on Integer literal | splice |
| InvalidMarker | marker not applied to code | definition |
| IrreducibleTypeFamily | irreducible type family application | definition |
| LitChar | Char literal | splice |
| LitDouble | Double literal | splice |
Expand Down Expand Up @@ -90,7 +111,10 @@ the splice before the plugin ran.
- runPluginM throws a located GHC diagnostic (PlinthDiagnostic, with
a [PLINTH-000NN] error code per error class) at the innermost span
in the error context, so GHC prints the "File.hs:l:c: error:"
header and the source snippet with the caret.
header and the source snippet with the caret. If no context frame
has a span, the error is reported at the start of the module (see
Note [Every Plinth error has a location] in
plutus-tx-plugin:PlutusTx.Plugin.Common).
- The Core shown in "Context:" frames is rendered with the GHC
suppression flags (no occurrence info, coercions, uniques, ticks)
and with the anchor/unsupported markers stripped.
Expand All @@ -116,6 +140,12 @@ When you fix one of these, update the golden files.
that contain Plinth code, or stripping the markers with a cheap
Core pass after the Plinth pass.

4. The goldens cover the error codes that user code can trigger:
PLINTH-00002, PLINTH-00004, PLINTH-00005 and PLINTH-00006.
PLINTH-00001, PLINTH-00003 and PLINTH-00007 are internal errors of
the compiler. No known source program triggers them, so no case
pins their location.

## Notes on the runner

The runner normalizes the output before the comparison: it strips
Expand Down
15 changes: 15 additions & 0 deletions plinth/test/errors/cases/CrossModule.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{-# LANGUAGE TemplateHaskell #-}
-- Unsupported construct in a function of another module: the error
-- must point at the offending code in CrossModuleHelper.hs, not at the
-- splice of this module.
module CrossModule where

import CrossModuleHelper (checked)
import PlutusTx
import qualified PlutusTx.Prelude as P

twice :: Integer -> Integer
twice i = checked i P.+ checked i

code :: CompiledCode (Integer -> Integer)
code = $$(PlutusTx.compile [|| twice ||])
8 changes: 8 additions & 0 deletions plinth/test/errors/cases/CrossModuleHelper.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Helper for the CrossModule case: a function of another module that
-- uses a construct that Plinth does not support. It has no pragma.
module CrossModuleHelper (checked) where

import qualified PlutusTx.Prelude as P

checked :: Integer -> Integer
checked n = if n P.< 0 then error "negative" else n
9 changes: 9 additions & 0 deletions plinth/test/errors/cases/InvalidMarker.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Misused compiler marker: 'plinthc' is not applied to the code to
-- compile (PLINTH-00006).
module InvalidMarker where

import PlutusTx
import PlutusTx.Plugin.Utils (plinthc)

code :: Integer -> CompiledCode Integer
code = plinthc
8 changes: 8 additions & 0 deletions plinth/test/errors/golden/9.12/CrossModule.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CrossModuleHelper.hs:8:29: error: [PLINTH-00004]
Plinth Compilation Error:
Context: Compiling code at CrossModuleHelper.hs:8:29-33:
GHC.Internal.Err.error
Error: Unsupported feature: GHC.Internal.Err.error, use PlutusTx.Prelude.error or PlutusTx.Prelude.traceError
|
8 | checked n = if n P.< 0 then error "negative" else n
| ^^^^^
7 changes: 7 additions & 0 deletions plinth/test/errors/golden/9.12/InvalidMarker.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
InvalidMarker.hs:9:1: error: [PLINTH-00006]
Plinth Compilation Error:
Context: Compiling definition at InvalidMarker.hs:9:1-4: code
Error: Found invalid marker, not applied correctly in expression plinthc
|
9 | code = plinthc
| ^^^^
8 changes: 8 additions & 0 deletions plinth/test/errors/golden/9.12/nolocs/CrossModule.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CrossModuleHelper.hs:8:29: error: [PLINTH-00004]
Plinth Compilation Error:
Context: Compiling code at CrossModuleHelper.hs:8:29-33:
GHC.Internal.Err.error
Error: Unsupported feature: GHC.Internal.Err.error, use PlutusTx.Prelude.error or PlutusTx.Prelude.traceError
|
8 | checked n = if n P.< 0 then error "negative" else n
| ^^^^^
22 changes: 22 additions & 0 deletions plinth/test/errors/golden/9.12/nolocs/DeepChain.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
DeepChain.hs:15:1: error: [PLINTH-00005]
Plinth Compilation Error:
Context: Compiling definition at DeepChain.hs:15:1-5: DeepChain.outer
Context: Compiling code:
\ (i :: GHC.Num.Integer.Integer) ->
NoUnfoldingHelper.opaque
(case i of x1 { __DEFAULT ->
PlutusTx.Builtins.Internal.addInteger x1 (GHC.Num.Integer.IS 1#)
})
Context: Compiling code:
NoUnfoldingHelper.opaque
(case i of x1 { __DEFAULT ->
PlutusTx.Builtins.Internal.addInteger x1 (GHC.Num.Integer.IS 1#)
})
Context: Compiling code:
NoUnfoldingHelper.opaque
Error: Reference to a name which is not a local, a builtin, or an external function with an available definition: Variable NoUnfoldingHelper.opaque
No unfolding
The definition of ‘NoUnfoldingHelper.opaque’ is not available. Remove its NOINLINE or OPAQUE pragma.
|
15 | outer i = inner (i P.+ 1)
| ^^^^^
8 changes: 8 additions & 0 deletions plinth/test/errors/golden/9.12/nolocs/EnumMethod.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
EnumMethod.hs:9:10: error: [PLINTH-00004]
Plinth Compilation Error:
Context: Compiling code at EnumMethod.hs:9:10-61:
GHC.Internal.Enum.$fEnumInteger_$csucc
Error: Unsupported feature: GHC.Internal.Enum.Enum.succ, use PlutusTx.Enum.Enum
|
9 | code = $$(PlutusTx.compile [|| \x -> succ (x :: Integer) ||])
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8 changes: 8 additions & 0 deletions plinth/test/errors/golden/9.12/nolocs/EnumRange.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
EnumRange.hs:8:10: error: [PLINTH-00004]
Plinth Compilation Error:
Context: Compiling code at EnumRange.hs:8:10-58:
GHC.Internal.Enum.$fEnumInteger_$cenumFromTo
Error: Unsupported feature: Range syntax, use PlutusTx.Enum.enumFromTo or PlutusTx.Enum.enumFromThenTo
|
8 | code = $$(PlutusTx.compile [|| [1 .. 10] :: [Integer] ||])
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
EnumRangeUnbounded.hs:8:10: error: [PLINTH-00004]
Plinth Compilation Error:
Context: Compiling code at EnumRangeUnbounded.hs:8:10-55:
GHC.Internal.Enum.$fEnumInteger_$cenumFrom
Error: Unsupported feature: Unbounded range syntax: unbounded ranges are not supported
|
8 | code = $$(PlutusTx.compile [|| [1 ..] :: [Integer] ||])
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9 changes: 9 additions & 0 deletions plinth/test/errors/golden/9.12/nolocs/Existential.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Existential.hs:11:1: error: [PLINTH-00004]
Plinth Compilation Error:
Context: Compiling definition at Existential.hs:11:1-5: Existential.mkBox
Context: Compiling type: GHC.Num.Integer.Integer -> Existential.Box
Context: Compiling type: Existential.Box
Error: Unsupported feature: Existential quantification in data constructor Existential.Box
|
11 | mkBox = Box
| ^^^^^
7 changes: 7 additions & 0 deletions plinth/test/errors/golden/9.12/nolocs/GadtExtension.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GadtExtension.hs:15:1: error: [PLINTH-00004]
Plinth Compilation Error:
Context: Compiling definition at GadtExtension.hs:15:1-4: code
Error: Unsupported feature: Following extensions are not supported: GADTs
|
15 | code = $$(PlutusTx.compile [|| eval ||])
| ^^^^
8 changes: 8 additions & 0 deletions plinth/test/errors/golden/9.12/nolocs/HaskellEq.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
HaskellEq.hs:9:10: error: [PLINTH-00004]
Plinth Compilation Error:
Context: Compiling code at HaskellEq.hs:9:10-62:
GHC.Num.Integer.integerEq
Error: Unsupported feature: GHC.Classes.Eq.==, use PlutusTx.Eq.Eq
|
9 | code = $$(PlutusTx.compile [|| \x -> x == (42 :: Integer) ||])
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8 changes: 8 additions & 0 deletions plinth/test/errors/golden/9.12/nolocs/HaskellOrd.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
HaskellOrd.hs:9:10: error: [PLINTH-00004]
Plinth Compilation Error:
Context: Compiling code at HaskellOrd.hs:9:10-61:
GHC.Num.Integer.integerLt
Error: Unsupported feature: GHC.Classes.Ord.<, use PlutusTx.Ord.Ord
|
9 | code = $$(PlutusTx.compile [|| \x -> x < (42 :: Integer) ||])
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8 changes: 8 additions & 0 deletions plinth/test/errors/golden/9.12/nolocs/HaskellShow.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
HaskellShow.hs:9:10: error: [PLINTH-00004]
Plinth Compilation Error:
Context: Compiling code at HaskellShow.hs:9:10-61:
GHC.Internal.Show.$fShowInteger_$cshow
Error: Unsupported feature: GHC.Internal.Show.Show.show, use PlutusTx.Show.Show
|
9 | code = $$(PlutusTx.compile [|| \x -> show (x :: Integer) ||])
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13 changes: 13 additions & 0 deletions plinth/test/errors/golden/9.12/nolocs/IOAction.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
IOAction.hs:8:10: error: [PLINTH-00004]
Plinth Compilation Error:
Context: Compiling code at IOAction.hs:8:10-54:
(GHC.Internal.Base.$fApplicativeIO5 @())
`cast` <Co:6> :: GHC.Types.Coercible
(()
-> GHC.Prim.State# GHC.Prim.RealWorld
-> (# GHC.Prim.State# GHC.Prim.RealWorld, () #))
(() -> GHC.Types.IO ())
Error: Unsupported feature: IO actions are not supported in Plinth
|
8 | code = $$(PlutusTx.compile [|| return () :: IO () ||])
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
81 changes: 81 additions & 0 deletions plinth/test/errors/golden/9.12/nolocs/IntegerPatternMatch.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
IntegerPatternMatch.hs:8:1: error: [PLINTH-00004]
Plinth Compilation Error:
Context: Compiling definition at IntegerPatternMatch.hs:8:1-8: IntegerPatternMatch.isAnswer
Context: Compiling code:
\ (ds :: GHC.Num.Integer.Integer) ->
case ds of x1 { __DEFAULT ->
case case x1 of {
GHC.Num.Integer.IS x ->
case x of {
__DEFAULT -> 0#;
42# -> 1#
};
GHC.Num.Integer.IP _ -> 0#;
GHC.Num.Integer.IN _ -> 0#
}
of {
__DEFAULT -> GHC.Types.False;
1# -> GHC.Types.True
}
}
Context: Compiling code:
case ds of x1 { __DEFAULT ->
case case x1 of {
GHC.Num.Integer.IS x ->
case x of {
__DEFAULT -> 0#;
42# -> 1#
};
GHC.Num.Integer.IP _ -> 0#;
GHC.Num.Integer.IN _ -> 0#
}
of {
__DEFAULT -> GHC.Types.False;
1# -> GHC.Types.True
}
}
Context: Compiling code:
case case x1 of {
GHC.Num.Integer.IS x ->
case x of {
__DEFAULT -> 0#;
42# -> 1#
};
GHC.Num.Integer.IP _ -> 0#;
GHC.Num.Integer.IN _ -> 0#
}
of {
__DEFAULT -> GHC.Types.False;
1# -> GHC.Types.True
}
Context: Compiling code:
case x1 of {
GHC.Num.Integer.IS x ->
case x of {
__DEFAULT -> 0#;
42# -> 1#
};
GHC.Num.Integer.IP _ -> 0#;
GHC.Num.Integer.IN _ -> 0#
}
Context: Creating instantiated matcher for 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'.
|
8 | isAnswer 42 = True
| ^^^^^^^^
7 changes: 7 additions & 0 deletions plinth/test/errors/golden/9.12/nolocs/InvalidMarker.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
InvalidMarker.hs:9:1: error: [PLINTH-00006]
Plinth Compilation Error:
Context: Compiling definition at InvalidMarker.hs:9:1-4: code
Error: Found invalid marker, not applied correctly in expression plinthc
|
9 | code = plinthc
| ^^^^
10 changes: 10 additions & 0 deletions plinth/test/errors/golden/9.12/nolocs/IrreducibleTypeFamily.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
IrreducibleTypeFamily.hs:11:1: error: [PLINTH-00004]
Plinth Compilation Error:
Context: Compiling definition at IrreducibleTypeFamily.hs:11:1-8: IrreducibleTypeFamily.identity
Context: Compiling type: IrreducibleTypeFamily.F GHC.Num.Integer.Integer
-> IrreducibleTypeFamily.F GHC.Num.Integer.Integer
Context: Compiling type: IrreducibleTypeFamily.F GHC.Num.Integer.Integer
Error: Unsupported feature: Irreducible type family application: IrreducibleTypeFamily.F
|
11 | identity x = x
| ^^^^^^^^
11 changes: 11 additions & 0 deletions plinth/test/errors/golden/9.12/nolocs/LitChar.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
LitChar.hs:8:1: error: [PLINTH-00004]
Plinth Compilation Error:
Context: Compiling definition at LitChar.hs:8:1-4: code
Context: Compiling code:
GHC.Types.C# 'x'#
Context: Compiling code:
'x'#
Error: Unsupported feature: Literal char
|
8 | code = $$(PlutusTx.compile [|| 'x' ||])
| ^^^^
13 changes: 13 additions & 0 deletions plinth/test/errors/golden/9.12/nolocs/LitDouble.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
LitDouble.hs:8:1: error: [PLINTH-00004]
Plinth Compilation Error:
Context: Compiling definition at LitDouble.hs:8:1-4: code
Context: Compiling code:
GHC.Types.D# 1.5##
Context: Compiling code:
GHC.Types.D#
Context: Compiling data constructor type: GHC.Types.D#
Context: Compiling type: GHC.Prim.Double#
Error: Unsupported feature: Type constructor: GHC.Prim.Double#
|
8 | code = $$(PlutusTx.compile [|| 1.5 :: Double ||])
| ^^^^
11 changes: 11 additions & 0 deletions plinth/test/errors/golden/9.12/nolocs/LitString.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
LitString.hs:9:1: error: [PLINTH-00004]
Plinth Compilation Error:
Context: Compiling definition at LitString.hs:9:1-4: code
Context: Compiling code:
GHC.CString.unpackCString# "hello"#
Context: Compiling code:
"hello"#
Error: Unsupported feature: Literal string (maybe you need to use OverloadedStrings)
|
9 | code = $$(PlutusTx.compile [|| "hello" ||])
| ^^^^
Loading
Loading