1
0
forked from GitHub/gf-core

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.

This commit is contained in:
aarne
2014-02-01 13:10:36 +00:00
parent 4cc72722a6
commit 2552b859fd
2 changed files with 7 additions and 0 deletions

View File

@@ -101,10 +101,15 @@ renameIdentTerm' env@(act,imps) t0 =
text "given" <+> fsep (punctuate comma (map (ppIdent . fst) qualifs))) text "given" <+> fsep (punctuate comma (map (ppIdent . fst) qualifs)))
fs -> case nub [f c | f <- fs] of fs -> case nub [f c | f <- fs] of
[tr] -> return tr [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 $$ ts@(t:_) -> do checkWarn (text "atomic term" <+> ppTerm Qualified 0 t0 $$
text "conflict" <+> hsep (punctuate comma (map (ppTerm Qualified 0) ts)) $$ text "conflict" <+> hsep (punctuate comma (map (ppTerm Qualified 0) ts)) $$
text "given" <+> fsep (punctuate comma (map (ppIdent . fst) qualifs))) text "given" <+> fsep (punctuate comma (map (ppIdent . fst) qualifs)))
return t return t
-}
-- a warning will be generated in CheckGrammar, and the head returned -- a warning will be generated in CheckGrammar, and the head returned
-- in next V: -- in next V:
-- Bad $ "conflicting imports:" +++ unwords (map prt ts) -- Bad $ "conflicting imports:" +++ unwords (map prt ts)

View File

@@ -398,6 +398,8 @@ data Term =
| ELincat Ident Term -- ^ boxed linearization type of Ident | ELincat Ident Term -- ^ boxed linearization type of Ident
| ELin Ident Term -- ^ boxed linearization of type 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 ; ... }@ | FV [Term] -- ^ alternatives in free variation: @variants { s ; ... }@
| Alts Term [(Term, Term)] -- ^ alternatives by prefix: @pre {t ; s\/c ; ...}@ | Alts Term [(Term, Term)] -- ^ alternatives by prefix: @pre {t ; s\/c ; ...}@