Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest to use Integer instead of Int for Data, Lift and Typeable (fix #3161). #3170

Merged
merged 2 commits into from
May 12, 2021
Merged
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
20 changes: 15 additions & 5 deletions plutus-tx/src/PlutusTx/IsData/Class.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-strictness #-}
{-# OPTIONS_GHC -fno-specialise #-}
module PlutusTx.IsData.Class where

import Data.ByteString as BS

import Prelude (Integer, Maybe (..))
import Prelude (Int, Integer, Maybe (..), error)

import PlutusTx.Data

@@ -18,6 +20,9 @@ import PlutusTx.Traversable
import Data.Kind
import Data.Void

import GHC.TypeLits (ErrorMessage (..), TypeError)


{-# ANN module "HLint: ignore" #-}

-- | A typeclass for types that can be converted to and from 'Data'.
@@ -32,6 +37,11 @@ instance IsData Data where
{-# INLINABLE fromData #-}
fromData d = Just d

instance (TypeError ('Text "Int is not supported, use Integer instead"))
=> IsData Int where
toData = error "unsupported"
fromData = error "unsupported"

instance IsData Integer where
{-# INLINABLE toData #-}
toData = I
11 changes: 11 additions & 0 deletions plutus-tx/src/PlutusTx/Lift/Instances.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
@@ -22,6 +23,8 @@ import PlutusIR.MkPir
import qualified Data.ByteString as BS
import Data.Proxy

import GHC.TypeLits (ErrorMessage (..), TypeError)

-- Derived instances

-- This instance ensures that we can apply typeable type constructors to typeable arguments and get a typeable
@@ -61,6 +64,14 @@ liftBuiltin
=> a -> RTCompile uni fun (Term TyName Name uni fun ())
liftBuiltin = pure . mkConstant ()

instance (TypeError ('Text "Int is not supported, use Integer instead"))
=> Typeable uni Int where
typeRep = Prelude.error "unsupported"

instance (TypeError ('Text "Int is not supported, use Integer instead"))
=> Lift uni Int where
lift = Prelude.error "unsupported"

instance uni `PLC.Includes` Integer => Typeable uni Integer where
typeRep = typeRepBuiltin