Fix `ligoLayout`

Description

Creating a custom generic instance for the types below using ligoLayout fails.

Steps to reproduce

Example 1

data CreateGameParam = CreateGameParam
  { cgpGameId :: Natural
  }

data PayFeeParam = PayFeeParam
  { pfpGameId :: Natural
  }

data Parameter
  = Create_game CreateGameParam
  | Pay_fee PayFeeParam
  | Destroy

customGeneric "CreateGameParam" ligoLayout
customGeneric "PayFeeParam" ligoLayout
customGeneric "Parameter" ligoLayout

The last line fails to compile:

The exact Name ‘v0_a1yiD’ is not in scope
  Probable cause: you used a unique Template Haskell name (NameU), 
  perhaps via newName, but did not bind it
  If that's it, then -ddump-splices might be useful

Example 2

If we change | Destroy to | Destroy (), the error message is now:

• Couldn't match type ‘PayFeeParam’ with ‘()’
  Expected type: GHC.Generics.Rep Parameter x
    Actual type: GHC.Generics.M1
                   GHC.Generics.D
                   ('GHC.Generics.MetaData
                      "Parameter" "Lorentz.Contracts.Sge" "fake_uid" 'False)
                   ((GHC.Generics.C1
                       ('GHC.Generics.MetaCons "Create_game" 'GHC.Generics.PrefixI 'False)
                       (GHC.Generics.S1
                          ('GHC.Generics.MetaSel
                             'Nothing
                             'GHC.Generics.NoSourceUnpackedness
                             'GHC.Generics.NoSourceStrictness
                             'GHC.Generics.DecidedStrict)
                          (GHC.Generics.Rec0 CreateGameParam))
                     GHC.Generics.:+: GHC.Generics.M1
                                        GHC.Generics.C
                                        ('GHC.Generics.MetaCons
                                           "Destroy" 'GHC.Generics.PrefixI 'False)
                                        (GHC.Generics.M1
                                           GHC.Generics.S
                                           ('GHC.Generics.MetaSel
                                              'Nothing
                                              'GHC.Generics.NoSourceUnpackedness
                                              'GHC.Generics.NoSourceStrictness
                                              'GHC.Generics.DecidedStrict)
                                           (GHC.Generics.K1 GHC.Generics.R PayFeeParam)))
                    GHC.Generics.:+: GHC.Generics.C1
                                       ('GHC.Generics.MetaCons
                                          "Pay_fee" 'GHC.Generics.PrefixI 'False)
                                       (GHC.Generics.S1
                                          ('GHC.Generics.MetaSel
                                             'Nothing
                                             'GHC.Generics.NoSourceUnpackedness
                                             'GHC.Generics.NoSourceStrictness
                                             'GHC.Generics.DecidedStrict)
                                          (GHC.Generics.Rec0 PayFeeParam)))
                   x

Example 3

This probably fails for the same reason as example #2 (closed), the error message is very similar:

data CreateGameParam = CreateGameParam
  { cgpGameId :: Natural
  }

data PayFeeParam = PayFeeParam
  { pfpGameId :: Natural
  }

data RegisterPlayer2Param = RegisterPlayer2Param
  { rp2pGameId :: Natural
  , rp2pPlayer2 :: Address
  }

data SetGameAuthorityParam = SetGameAuthorityParam
  { sgapGameAuthority :: Address
  }

data SetFeeCollectorParam = SetFeeCollectorParam
  { sfcpFeeCollector :: Address
  }

data Parameter
  = Create_game CreateGameParam
  | Pay_fee PayFeeParam
  | Register_player2 RegisterPlayer2Param
  | Set_game_authority SetGameAuthorityParam
  | Set_fee_collector SetFeeCollectorParam

customGeneric "CreateGameParam" ligoLayout
customGeneric "PayFeeParam" ligoLayout
customGeneric "RegisterPlayer2Param" ligoLayout
customGeneric "SetGameAuthorityParam" ligoLayout
customGeneric "SetFeeCollectorParam" ligoLayout

customGeneric "Parameter" ligoLayout
• Couldn't match type ‘SetGameAuthorityParam’
                 with ‘SetFeeCollectorParam’
  Expected type: GHC.Generics.Rep Parameter x
    Actual type: GHC.Generics.M1
                   ...

Expected behaviour

I expected all the examples above to compile successfully.

Actual behaviour

The examples above fail to compile, with the indicated error messages.

Note that if we manual reorder the Parameter's constructors to be in alphabetical order, then it does compile successfully, e.g.:

data Parameter
  = Create_game CreateGameParam
  | Destroy
  | Pay_fee PayFeeParam

Environment

master branch, 5592a1451b9080da208f8bd10460bd3bb6f5c5d7, 2021/03/01

Edited by Diogo Castro