diff options
| author | aarne <unknown> | 2005-02-15 10:06:30 +0000 |
|---|---|---|
| committer | aarne <unknown> | 2005-02-15 10:06:30 +0000 |
| commit | f8df4df53065fdafc76306e20e5e12b335254042 (patch) | |
| tree | d1cb99ac2114eb7cc289a71e6be1fb8bbb72f82f /src/GF/Grammar/Macros.hs | |
| parent | 1befa19e222c0c44142696e4aaf7d942ae348653 (diff) | |
record type extension freshness check
Diffstat (limited to 'src/GF/Grammar/Macros.hs')
| -rw-r--r-- | src/GF/Grammar/Macros.hs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/GF/Grammar/Macros.hs b/src/GF/Grammar/Macros.hs index cfc71b1a5..cb4dcc526 100644 --- a/src/GF/Grammar/Macros.hs +++ b/src/GF/Grammar/Macros.hs @@ -339,13 +339,17 @@ mkFunType tt t = mkProd ([(wildIdent, ty) | ty <- tt], t, []) -- nondep prod plusRecType :: Type -> Type -> Err Type plusRecType t1 t2 = case (unComputed t1, unComputed t2) of - (RecType r1, RecType r2) -> return (RecType (r1 ++ r2)) + (RecType r1, RecType r2) -> case + filter (`elem` (map fst r1)) (map fst r2) of + [] -> return (RecType (r1 ++ r2)) + ls -> Bad $ "clashing labels" +++ unwords (map prt ls) _ -> Bad ("cannot add record types" +++ prt t1 +++ "and" +++ prt t2) plusRecord :: Term -> Term -> Err Term plusRecord t1 t2 = case (t1,t2) of - (R r1, R r2 ) -> return (R (r1 ++ r2)) + (R r1, R r2 ) -> return (R ([(l,v) | -- overshadowing of old fields + (l,v) <- r1, not (elem l (map fst r2)) ] ++ r2)) (_, FV rs) -> mapM (plusRecord t1) rs >>= return . FV (FV rs,_ ) -> mapM (`plusRecord` t2) rs >>= return . FV _ -> Bad ("cannot add records" +++ prt t1 +++ "and" +++ prt t2) |
