From a0cbe84f1da16337711c2d50ad7b7d3a8f045c15 Mon Sep 17 00:00:00 2001 From: Michael Sondergaard Date: Mon, 4 Nov 2013 19:57:43 +0100 Subject: [PATCH 1/4] Throw an error when deserializing a bad type This error should never be encountered, as long as we always update the get function when the put function is, as required by get . put == id. --- compiler/SourceSyntax/Type.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/SourceSyntax/Type.hs b/compiler/SourceSyntax/Type.hs index 635f156..7c73243 100644 --- a/compiler/SourceSyntax/Type.hs +++ b/compiler/SourceSyntax/Type.hs @@ -93,4 +93,5 @@ instance Binary Type where 1 -> Var <$> get 2 -> Data <$> get <*> get 3 -> return EmptyRecord - 4 -> Record <$> get <*> get \ No newline at end of file + 4 -> Record <$> get <*> get + _ -> error "Error reading a valid type from serialized string" From 67924d1c8ab8a0e3a660868bd9b7a8b3b335f8dd Mon Sep 17 00:00:00 2001 From: Michael Sondergaard Date: Mon, 4 Nov 2013 20:05:04 +0100 Subject: [PATCH 2/4] Remove catch-all match in Declaration These ought to actually be written out, as the previous TODO message stated, but at least this way the compiler will warn us when adding a new Decl. --- compiler/SourceSyntax/Declaration.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/SourceSyntax/Declaration.hs b/compiler/SourceSyntax/Declaration.hs index cb47753..717300f 100644 --- a/compiler/SourceSyntax/Declaration.hs +++ b/compiler/SourceSyntax/Declaration.hs @@ -43,6 +43,7 @@ instance Pretty (Declaration t v) where let alias = P.text name <+> P.hsep (map P.text tvars) in P.hang (P.text "type" <+> alias <+> P.equals) 4 (pretty tipe) - -- TODO: actually write out the other cases. They are currently unused, but - -- this is probably going to be a bug someday. - _ -> P.text (show decl) \ No newline at end of file + -- TODO: Actually write out the contained data in these cases. + ImportEvent _ _ _ _ -> P.text (show decl) + ExportEvent _ _ _ -> P.text (show decl) + Fixity _ _ _ -> P.text (show decl) From 4a111890ed898c83616a9feffc284f952a011c1c Mon Sep 17 00:00:00 2001 From: Michael Sondergaard Date: Mon, 4 Nov 2013 20:13:31 +0100 Subject: [PATCH 3/4] Add invalid serialization errors to Module.hs --- compiler/SourceSyntax/Module.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/SourceSyntax/Module.hs b/compiler/SourceSyntax/Module.hs index dfd2556..fab3774 100644 --- a/compiler/SourceSyntax/Module.hs +++ b/compiler/SourceSyntax/Module.hs @@ -42,6 +42,7 @@ instance Binary ImportMethod where 0 -> liftM As get 1 -> liftM Importing get 2 -> liftM Hiding get + _ -> error "Error valid ImportMethod type from serialized string" data MetadataModule t v = MetadataModule { names :: [String], @@ -83,6 +84,10 @@ instance Binary ModuleInterface where instance Binary Assoc where get = do n <- getWord8 - return $ case n of { 0 -> L ; 1 -> N ; 2 -> R } + return $ case n of + 0 -> L + 1 -> N + 2 -> R + _ -> error "Error reading valid associativity from serialized string" put assoc = putWord8 $ case assoc of { L -> 0 ; N -> 1 ; R -> 2 } From 158c70eee7a66b2cc14d4b10109cddbb8cc70aee Mon Sep 17 00:00:00 2001 From: Michael Sondergaard Date: Mon, 4 Nov 2013 21:09:22 +0100 Subject: [PATCH 4/4] Fix typo --- compiler/SourceSyntax/Module.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/SourceSyntax/Module.hs b/compiler/SourceSyntax/Module.hs index fab3774..d7fd31a 100644 --- a/compiler/SourceSyntax/Module.hs +++ b/compiler/SourceSyntax/Module.hs @@ -42,7 +42,7 @@ instance Binary ImportMethod where 0 -> liftM As get 1 -> liftM Importing get 2 -> liftM Hiding get - _ -> error "Error valid ImportMethod type from serialized string" + _ -> error "Error reading valid ImportMethod type from serialized string" data MetadataModule t v = MetadataModule { names :: [String],