agentm / project-m36

Project: M36 Relational Algebra Engine
The Unlicense
876 stars 47 forks source link

Atomable toAddTypeExpr fails when using multiple layers of indirection with "primitive type missing: <user-defined type>" #228

Closed lierdakil closed 5 years ago

lierdakil commented 5 years ago

Long story short, this fails (sorry, from the top of my head, might not compile):

{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}
import ProjectM36.Client
import GHC.Generics
import Data.Binary
import Control.DeepSeq
import Data.Proxy

data Typ1 = Typ1 Int
   deriving (Generic, Show, Eq, Binary, NFData, Atomable)
data Typ2 = Typ2 Int
   deriving (Generic, Show, Eq, Binary, NFData, Atomable)
data Typ3 = Typ31 Typ1 | Typ32 Typ2
   deriving (Generic, Show, Eq, Binary, NFData, Atomable)

main :: IO ()
main = print $ toAddTypeExpr (Proxy :: Proxy Typ3)

with a confusing error message of "primitive type missing: Typ1 []" (or something along that lines)

This is happening because it is assumed in the AtomableG (K1 c a) instance that data construction arguments are primitive, which is not always (or even usually) the case.

Commit a4d9247a2b3392abf28d31a845bb9b2535026f37 fixes this, and I ran some minimal tests, but I'm not sure if there are any unintended side effects. You might want to take a look regardless.

agentm commented 5 years ago

Ah- good catch. I'll add a test for that an merge it. Thanks!

agentm commented 5 years ago

Cherry-picked to master in a6efc3377805943fb6e3cdd65415dca871b2b3b5.