From d8f5707f244496d8fcceb16d15a2e827535cf428 Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Tue, 25 Jul 2017 22:15:06 -0700 Subject: [PATCH] Fix unmarshaling of objects in unions in Go Original commit 045c79bc033ffabfe8aacebb250fbc19a7f397e0 --- src/Golang.purs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Golang.purs b/src/Golang.purs index ac232a67..ec0ab59e 100644 --- a/src/Golang.purs +++ b/src/Golang.purs @@ -318,22 +318,22 @@ renderGolangUnion allTypes = do primitiveArgs <- mapM primitive $ L.fromFoldable [IRInteger, IRDouble, IRBool, IRString] compoundArgs <- mapM compound $ L.fromFoldable compoundPredicates pure $ intercalate ", " $ A.concat [A.fromFoldable primitiveArgs, A.fromFoldable compoundArgs] - memberArg :: String -> (String -> String) -> (IRType -> Boolean) -> Doc String + memberArg :: String -> (IRType -> String -> String) -> (IRType -> Boolean) -> Doc String memberArg notPresentValue renderPresent p = let { element } = removeElement p allTypes in case element of Just t -> do name <- unionFieldName t - pure $ renderPresent name + pure $ renderPresent t name Nothing -> pure notPresentValue primitiveUnmarshalArg t = - memberArg "nil" ("&x." <> _) (eq t) + memberArg "nil" (\_ n -> "&x." <> n) (eq t) compoundUnmarshalArg p = - memberArg "false, nil" ("true, &x." <> _) p + memberArg "false, nil" (\t n -> if isClass t then "true, &c" else "true, &x." <> n) p primitiveMarshalArg :: IRType -> Doc String primitiveMarshalArg t = - memberArg "nil" ("x." <> _) (eq t) + memberArg "nil" (\_ n -> "x." <> n) (eq t) compoundMarshalArg :: (IRType -> Boolean) -> Doc String compoundMarshalArg p = - memberArg "false, nil" (\n -> "x." <> n <> " != nil, x." <> n) p + memberArg "false, nil" (\t n -> "x." <> n <> " != nil, x." <> n) p