mlabs-haskell / mlabs-haskell/lambda-buffers

Plutarch: Using `s` type variable conflicts with the Plutarch scope `s` variable printed by default

Open
#231 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug codegen plutarch
Dominant language
Haskell
Stars
32
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Sample

record ScriptDatum s = {
  scriptType : s,
  -- ^ Protocol specific script type stored in this UTxO
  redeemer : AssetClass
  -- ^ Wallet containing `$redeemer` must sign the 'delete-script' transaction as an authorization method
}
derive Eq (ScriptDatum s)
derive PlutusData (ScriptDatum s)
derive Json (ScriptDatum s)

Error

       > [1 of 2] Compiling LambdaBuffers.Cardano.Extra.OneShot.Validation.Plutarch ( autogen/LambdaBuffers/Cardano/Extra/OneShot/Validation/Plutarch.hs, dist/build/LambdaBuffers/Cardano/Extra/OneShot/Validation/Plutarch.o, dist/build/LambdaBuffers/Cardano/Extra/OneShot/Validation/Plutarch.dyn_o )
       > [2 of 2] Compiling LambdaBuffers.Cardano.Extra.ScriptStorage.Validation.Plutarch ( autogen/LambdaBuffers/Cardano/Extra/ScriptStorage/Validation/Plutarch.hs, dist/build/LambdaBuffers/Cardano/Extra/ScriptStorage/Validation/Plutarch.o, dist/build/LambdaBuffers/Cardano/Extra/ScriptStorage/Validation/Plutarch.dyn_o )
       >
       > autogen/LambdaBuffers/Cardano/Extra/ScriptStorage/Validation/Plutarch.hs:31:18: error:
       >     Conflicting definitions for ‘s’
       >     Bound at: autogen/LambdaBuffers/Cardano/Extra/ScriptStorage/Validation/Plutarch.hs:31:18-38
       >               autogen/LambdaBuffers/Cardano/Extra/ScriptStorage/Validation/Plutarch.hs:31:40-56
       >    |
       > 31 | data ScriptDatum (s :: Plutarch.PType) (s :: Plutarch.S) = ScriptDatum (Plutarch.Term s (Plutarch.Builtin.PAsData s))
       >    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Workaround

Just use a different letter than s


record ScriptDatum a = {
  scriptType : a,
  -- ^ Protocol specific script type stored in this UTxO
  redeemer : AssetClass
  -- ^ Wallet containing `$redeemer` must sign the 'delete-script' transaction as an authorization method
}
derive Eq (ScriptDatum a)
derive PlutusData (ScriptDatum a)
derive Json (ScriptDatum a)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the ScriptDatum example and inspect the generator responsible for autogen/LambdaBuffers/Cardano/Extra/ScriptStorage/Validation/Plutarch.hs. Trace how the source type variable and Plutarch scope variable are named; done means generated Haskell uses distinct binders and compiles without the conflicting-definitions error.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.