From 6dba4e6f1e363162b887efff3336fec258e8737d Mon Sep 17 00:00:00 2001 From: aarne Date: Sat, 1 Feb 2014 13:10:36 +0000 Subject: [PATCH] ad hoc overloading: a new way to deal with name resolution conflicts. Previously the renamer warned if there was e.g. an unqualified reference to mkAdv, which could come from either Syntax or Paradigms. The renamer picked randomly one of the alternatives, which then often failed in type checking. Now, all candidates are collected into a new structure AdHocOverload [Term], which is accessed by the type checker to make the choice based on the type of the constant. This eliminates some of the warnings and some of the error due to wrong choices. In some rare cases, the inherited constants have the same type, which cannot be resolved by overloading. In such cases, the type checker does the same as the renamer did before: pick the "first" option (i.e. the one that happens to be the first in the list returned by the renamer) and issues a warning. In this patch, only a couple of lines are changed. The typechecker (RConcrete) has more substantial changes, and will be recorded as the next patch. --- src/compiler/GF/Compile/Rename.hs | 5 +++++ src/compiler/GF/Grammar/Grammar.hs | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/compiler/GF/Compile/Rename.hs b/src/compiler/GF/Compile/Rename.hs index 732693b49..e2ee5934b 100644 --- a/src/compiler/GF/Compile/Rename.hs +++ b/src/compiler/GF/Compile/Rename.hs @@ -101,10 +101,15 @@ renameIdentTerm' env@(act,imps) t0 = text "given" <+> fsep (punctuate comma (map (ppIdent . fst) qualifs))) fs -> case nub [f c | f <- fs] of [tr] -> return tr + ts -> return $ AdHocOverload ts + -- name conflicts resolved as overloading in TypeCheck.RConcrete AR 31/1/2014 + -- the old definition is below and still presupposed in TypeCheck.Concrete +{- ts@(t:_) -> do checkWarn (text "atomic term" <+> ppTerm Qualified 0 t0 $$ text "conflict" <+> hsep (punctuate comma (map (ppTerm Qualified 0) ts)) $$ text "given" <+> fsep (punctuate comma (map (ppIdent . fst) qualifs))) return t +-} -- a warning will be generated in CheckGrammar, and the head returned -- in next V: -- Bad $ "conflicting imports:" +++ unwords (map prt ts) diff --git a/src/compiler/GF/Grammar/Grammar.hs b/src/compiler/GF/Grammar/Grammar.hs index 7400ff09b..2fdab29c7 100644 --- a/src/compiler/GF/Grammar/Grammar.hs +++ b/src/compiler/GF/Grammar/Grammar.hs @@ -398,6 +398,8 @@ data Term = | ELincat Ident Term -- ^ boxed linearization type of Ident | ELin Ident Term -- ^ boxed linearization of type Ident + | AdHocOverload [Term] -- ^ ad hoc overloading generated in Rename + | FV [Term] -- ^ alternatives in free variation: @variants { s ; ... }@ | Alts Term [(Term, Term)] -- ^ alternatives by prefix: @pre {t ; s\/c ; ...}@