File tree Expand file tree Collapse file tree 3 files changed +15
-3
lines changed
Expand file tree Collapse file tree 3 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -21,13 +21,20 @@ deriveBounded name = do
2121 , TH. datatypeCons = cons
2222 } <-
2323 TH. reifyDatatype name
24+
25+ roles <- reifyRoles name
26+
2427 let
2528 -- The purpose of the `TH.VarT . varTToName` roundtrip is to remove the kind
2629 -- signatures attached to the type variables in `tyVars0`. Otherwise, the
2730 -- `KindSignatures` extension would be needed whenever `length tyVars0 > 0`.
2831 tyVars = TH. VarT . varTToName <$> tyVars0
32+
33+ nonPhantomTyVars = VarT . varTToName . snd <$> filter ((/= PhantomR ) . fst ) (zip roles tyVars0)
34+
2935 instanceCxt :: TH. Cxt
30- instanceCxt = TH. AppT (TH. ConT ''Bounded) <$> tyVars
36+ instanceCxt = TH. AppT (TH. ConT ''Bounded) <$> nonPhantomTyVars
37+
3138 instanceType :: TH. Type
3239 instanceType = TH. AppT (TH. ConT ''Bounded) $ foldl' TH. AppT (TH. ConT tyConName) tyVars
3340
Original file line number Diff line number Diff line change 1+ instance PlutusTx.Bounded.Class.Bounded (Bounded.Spec.PhantomADT e_0)
2+ where {PlutusTx.Bounded.Class.minBound = Bounded.Spec.PhantomADT PlutusTx.Bounded.Class.minBound;
3+ {-# INLINABLE PlutusTx.Bounded.Class.minBound #-};
4+ PlutusTx.Bounded.Class.maxBound = Bounded.Spec.PhantomADT PlutusTx.Bounded.Class.maxBound;
5+ {-# INLINABLE PlutusTx.Bounded.Class.maxBound #-}}
Original file line number Diff line number Diff line change @@ -42,13 +42,13 @@ boundedTests =
4242 in testGroup
4343 " PlutusTx.Enum tests"
4444 [ testCase " conforms to haskell" $ (Tx. minBound @ SomeVeryLargeEnum , Tx. maxBound @ SomeVeryLargeEnum ) @?= (HS. minBound , HS. maxBound )
45- , -- currently does not work with polymorphic phantom types, remove the type annotation when support is added
46- testCase " phantom" $ Tx. minBound @ (PhantomADT () ) @?= HS. minBound
45+ , testCase " phantom" $ Tx. minBound @ (PhantomADT () ) @?= HS. minBound
4746 , runTestNested
4847 [" test" , " Bounded" , " Golden" ]
4948 [ $ (goldenCodeGen " SomeVeryLargeEnum" (deriveBounded ''SomeVeryLargeEnum))
5049 , $ (goldenCodeGen " Unit" (deriveBounded ''() ))
5150 , $ (goldenCodeGen " Ordering" (deriveBounded ''Ordering))
5251 , $ (goldenCodeGen " SingleConstructor" (deriveBounded ''SingleConstructor))
52+ , $ (goldenCodeGen " PhantomADT" (deriveBounded ''PhantomADT))
5353 ]
5454 ]
You can’t perform that action at this time.
0 commit comments