Skip to content

Commit 9b33209

Browse files
committed
[ fix ] Better error message on derivation of a primitive type
1 parent db177c1 commit 9b33209

7 files changed

Lines changed: 48 additions & 4 deletions

File tree

src/Deriving/DepTyCheck/Gen/ForAllNeededTypes/Impl.idr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ deriveAll weightFunTys decls {cc=(alreadyDerived, _)}= do
4646
else do
4747
(niit, cr) <- updateNamesAndConsRecs $ targetType <$> toList toDeriveUnknown
4848
put (toDeriveUnknown, empty)
49-
assert_total $ deriveAll @{niit} @{cr} {cc=(alreadyDerived `union` toDeriveUnknown, %search)} weightFunTys decls
49+
assert_total $ deriveAll @{niit} @{cr} {cc=(alreadyDerived, %search)} weightFunTys decls
5050
where
5151
deriveOne : GenSignature -> m (List TypeInfo, Decl, Decl)
5252
deriveOne sig = do
@@ -66,10 +66,12 @@ DeriveBodyForType => ClosuringContext m => Elaboration m => SortedMap GenSignatu
6666
logValue Details "deptycheck.derive.closuring.external" [sig] "is used as an external generator" $
6767
(callExternalGen extSig name (var outmostFuelArg) $ rewrite lenEq in values, Just (_ ** extSig.gendOrder))
6868

69-
-- put to derivation queue if necessary
70-
when (not $ List.Set.contains sig %search) $ do
69+
-- check if internal generator asked for is for a primitive type
70+
when (isTypeInfoPrim sig.targetType) $
71+
fail "Cannot derive generator for the primitive type \{show $ extractTargetTyExpr sig.targetType}, use external instead"
7172

72-
-- remember the task to derive
73+
-- remember the task to derive, if necessary
74+
when (not $ List.Set.contains sig %search) $ do
7375
modify $ if isTypeKnown sig.targetType then mapFst $ normalise . List.Set.insert sig else mapSnd $ normalise . List.Set.insert sig
7476

7577
-- call the internal gen

src/Deriving/DepTyCheck/Util/Primitives.idr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,12 @@ extractTargetTyExpr $ MkTypeInfo (NS (MkNS ["^prim^"]) $ UN $ Basic "Double" ) [
5050
extractTargetTyExpr $ MkTypeInfo (NS (MkNS ["^prim^"]) $ UN $ Basic "%World" ) [] [] = primVal $ PrT WorldType
5151
extractTargetTyExpr $ MkTypeInfo (NS (MkNS ["^prim^"]) $ UN $ Basic "Type" ) [] [] = type
5252
extractTargetTyExpr ti = var ti.name
53+
54+
export
55+
isTypeInfoPrim : TypeInfo -> Bool
56+
isTypeInfoPrim $ MkTypeInfo (NS (MkNS ["^prim^"]) $ UN $ Basic s) [] [] = True
57+
isTypeInfoPrim _ = False
58+
--isTypeInfoPrim = not . isVar . extractTragetTyExpr
59+
60+
0 isTypeInfoPrim_correct : (s : String) -> isTypeInfoPrim (primTypeInfo s) = True
61+
isTypeInfoPrim_correct s = Refl
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module DerivedGen
2+
3+
import RunDerivedGen
4+
5+
%default total
6+
7+
%language ElabReflection
8+
9+
data X = MkX String
10+
11+
checkedGen : Fuel -> Gen MaybeEmpty X
12+
checkedGen = deriveGen
13+
14+
Show X where
15+
show (MkX s) = "MkX \{show s}"
16+
17+
main : IO ()
18+
main = runGs [ G checkedGen ]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../_common/RunDerivedGen.idr
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../_common/derive.ipkg
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
1/2: Building RunDerivedGen (RunDerivedGen.idr)
2+
2/2: Building DerivedGen (DerivedGen.idr)
3+
Error: While processing right hand side of checkedGen. Error during reflection: Cannot derive generator for the primitive type String, use external instead
4+
5+
DerivedGen:1
6+
08 |
7+
09 | data X = MkX String
8+
10 |
9+
11 | checkedGen : Fuel -> Gen MaybeEmpty X
10+
12 | checkedGen = deriveGen
11+
^^^^^^^^^
12+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../_common/run

0 commit comments

Comments
 (0)