mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
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."
This commit is contained in:
@@ -160,7 +160,8 @@ inferLType gr g trm = case trm of
|
|||||||
checkLType gr g trm (Table arg val)
|
checkLType gr g trm (Table arg val)
|
||||||
V arg pts -> do
|
V arg pts -> do
|
||||||
(_,val) <- checks $ map (inferLType gr g) pts
|
(_,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
|
K s -> do
|
||||||
if elem ' ' s
|
if elem ' ' s
|
||||||
@@ -431,6 +432,12 @@ checkLType gr g trm typ0 = do
|
|||||||
cs' <- mapM (checkCase arg val) cs
|
cs' <- mapM (checkCase arg val) cs
|
||||||
return (T (TTyped arg) cs', typ)
|
return (T (TTyped arg) cs', typ)
|
||||||
_ -> checkError $ text "table type expected for table instead of" $$ nest 2 (ppType 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
|
R r -> case typ of --- why needed? because inference may be too difficult
|
||||||
RecType rr -> do
|
RecType rr -> do
|
||||||
|
|||||||
Reference in New Issue
Block a user