summaryrefslogtreecommitdiff
path: root/src/GF/Compile
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2007-05-31 09:58:38 +0000
committeraarne <aarne@cs.chalmers.se>2007-05-31 09:58:38 +0000
commit76268417db7dc617aaaae0214b0515d990a5c471 (patch)
tree7053078162863e866e3b7ede3fddbaca1efb7ae9 /src/GF/Compile
parent93b4888b7868205f09ee0002290675d86ed335d5 (diff)
overload checking and messages; resource.txt modifs
Diffstat (limited to 'src/GF/Compile')
-rw-r--r--src/GF/Compile/CheckGrammar.hs25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/GF/Compile/CheckGrammar.hs b/src/GF/Compile/CheckGrammar.hs
index 262980eb9..85da644c8 100644
--- a/src/GF/Compile/CheckGrammar.hs
+++ b/src/GF/Compile/CheckGrammar.hs
@@ -380,6 +380,12 @@ inferLType gr trm = case trm of
Q m ident | isPredef m -> termWith trm $ checkErr (typPredefined ident)
Q m ident -> checks [
+---- do
+---- over <- getOverload gr Nothing trm
+---- case over of
+---- Just trty -> return trty
+---- _ -> fail "not overloaded"
+---- ,
termWith trm $ checkErr (lookupResType gr m ident) >>= comp
,
checkErr (lookupResDef gr m ident) >>= infer
@@ -605,12 +611,13 @@ getOverload env@gr mt t = case appForm t of
let (tts,tys) = unzip ttys
let vfs = lookupOverloadInstance tys typs
- case [vf | vf@(v,f) <- vfs, elem mt [Nothing,Just v]] of
+ case [vf | vf@(v,f) <- vfs, matchVal mt v] of
[(val,fun)] -> return (mkApp fun tts, val)
[] -> raise $ "no overload instance of" +++ prt f +++
- maybe [] (("when expecting" +++) . prtType env) mt +++
"for" +++ unwords (map (prtType env) tys) +++ "among" ++++
- unlines [unwords (map (prtType env) ty) | (ty,_) <- typs]
+ unlines [" " ++ unwords (map (prtType env) ty) | (ty,_) <- typs] ++
+ maybe [] (("with value type" +++) . prtType env) mt
+
---- ++++ "DEBUG" +++ unwords (map show tys) +++ ";"
---- ++++ unlines (map (show . fst) typs) ----
@@ -625,6 +632,10 @@ getOverload env@gr mt t = case appForm t of
"for" +++ unwords (map (prtType env) tys) ++++ "with alternatives" ++++
unlines [prtType env ty | (ty,_) <- vfs']
+ matchVal mt v = elem mt ([Nothing,Just v] ++ unlocked) where
+ unlocked = case v of
+ RecType fs -> [Just $ RecType $ filter (not . isLockLabel . fst) fs]
+ _ -> []
---- TODO: accept subtypes
---- TODO: use a trie
lookupOverloadInstance tys typs =
@@ -667,6 +678,14 @@ checkLType env trm typ0 = do
(trm',ty') <- infer trm
termWith trm' $ checkEq typ ty' trm'
+ Q _ _ -> do
+ over <- getOverload env (Just typ) trm
+ case over of
+ Just trty -> return trty
+ _ -> do
+ (trm',ty') <- infer trm
+ termWith trm' $ checkEq typ ty' trm'
+
T _ [] ->
prtFail "found empty table in type" typ
T _ cs -> case typ of