From 12d86604b243f51e92e30b4899ce30800ca8de04 Mon Sep 17 00:00:00 2001 From: hallgren Date: Tue, 12 Nov 2013 13:55:38 +0000 Subject: [PATCH] Fix Issue 68: Cannot use an overloaded operator in table defined using square brackets Add proper type checking of course-of-values tables: + Make sure that all subterms have the same type. + Resolve overloaded operators. Note though that the GF book states in C.4.12 that the "course-of-values table [...] format is not recommended for GF source code, since the ordering of parameter values is not specified and therefore a compiler-internal decision." --- src/compiler/GF/Compile/TypeCheck/Concrete.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/compiler/GF/Compile/TypeCheck/Concrete.hs b/src/compiler/GF/Compile/TypeCheck/Concrete.hs index b58e9f5a2..67634d4f1 100644 --- a/src/compiler/GF/Compile/TypeCheck/Concrete.hs +++ b/src/compiler/GF/Compile/TypeCheck/Concrete.hs @@ -160,7 +160,8 @@ inferLType gr g trm = case trm of checkLType gr g trm (Table arg val) V arg pts -> do (_,val) <- checks $ map (inferLType gr g) pts - return (trm, Table arg val) +-- return (trm, Table arg val) -- old, caused issue 68 + checkLType gr g trm (Table arg val) K s -> do if elem ' ' s @@ -431,6 +432,12 @@ checkLType gr g trm typ0 = do cs' <- mapM (checkCase arg val) cs return (T (TTyped arg) cs', typ) _ -> checkError $ text "table type expected for table instead of" $$ nest 2 (ppType typ) + V arg0 vs -> + case typ of + Table arg1 val -> + do arg' <- checkEqLType gr g arg0 arg1 trm + vs' <- map fst `fmap` sequence [checkLType gr g v val|v<-vs] + return (V arg' vs',typ) R r -> case typ of --- why needed? because inference may be too difficult RecType rr -> do