git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
More lenient overlap check
383a9efPhil Freeman
examples/failing/Superclasses4.pursnew file+12
@@ -0,0 +1,12 @@
1+module OverlappingInstances where
2+
3+class Foo a
4+
5+instance foo1 :: Foo Number
6+
7+instance foo2 :: Foo Number
8+
9+test :: forall a. (Foo a) => a -> a
10+test a = a
11+
12+test1 = test 0
examples/passing/Superclasses3.purs+1−1
@@ -7,7 +7,7 @@ import Control.Monad.Eff
7class (Monad m) <= MonadWriter w m where
7class (Monad m) <= MonadWriter w m where
8 tell :: w -> m {}
8 tell :: w -> m {}
9
9
10−testFunctor :: forall m. (Applicative m) => m Number -> m Number
10+testFunctor :: forall m. (Functor m) => m Number -> m Number
11testFunctor n = (+) 1 <$> n
11testFunctor n = (+) 1 <$> n
12
12
13test :: forall w m. (Monad m, MonadWriter w m) => w -> m {}
13test :: forall w m. (Monad m, MonadWriter w m) => w -> m {}
src/Language/PureScript/TypeChecker/Types.hs+14−4
@@ -306,10 +306,12 @@ entails env moduleName context = solve (sortedNubBy canonicalizeDictionary (filt
306 filterModule _ = False
306 filterModule _ = False
307
307
308 solve context' (className, tys) trySuperclasses =
308 solve context' (className, tys) trySuperclasses =
309+ let
309− case chooseSimplestDictionaries (go trySuperclasses className tys) of
310+ dicts = go trySuperclasses className tys
311+ in case sortedNubBy dictTrace (chooseSimplestDictionaries dicts) of
310− [] -> throwError . strMsg $ "No instance found for " ++ show className ++ " " ++ unwords (map prettyPrintTypeAtom tys)
312+ [] -> throwError . strMsg $ "No instance found for " ++ show className ++ " " ++ unwords (map prettyPrintTypeAtom tys)
311− [dict] -> return (dictionaryValueToValue dict)
313+ [_] -> return $ dictionaryValueToValue $ head dicts
312− _ -> throwError . strMsg $ "Overlapping instances found for " ++ show className ++ " " ++ unwords (map prettyPrintTypeAtom tys)
314+ _ -> throwError . strMsg $ "Overlapping instances found for " ++ show className ++ " " ++ unwords (map prettyPrintTypeAtom tys)
313 where
315 where
314 go trySuperclasses' className' tys' =
316 go trySuperclasses' className' tys' =
315 -- Look for regular type instances
317 -- Look for regular type instances
@@ -385,6 +387,14 @@ entails env moduleName context = solve (sortedNubBy canonicalizeDictionary (filt
385 isSimpleDictionaryValue SubclassDictionaryValue{} = False
387 isSimpleDictionaryValue SubclassDictionaryValue{} = False
386 isSimpleDictionaryValue (DependentDictionaryValue _ ds) = all isSimpleDictionaryValue ds
388 isSimpleDictionaryValue (DependentDictionaryValue _ ds) = all isSimpleDictionaryValue ds
387 isSimpleDictionaryValue _ = True
389 isSimpleDictionaryValue _ = True
390+ -- |
391+ -- Get the "trace" of a DictionaryValue - that is, remove all SubclassDictionaryValue
392+ -- data constructors
393+ --
394+ dictTrace :: DictionaryValue -> DictionaryValue
395+ dictTrace (DependentDictionaryValue fnName dicts) = DependentDictionaryValue fnName $ map dictTrace dicts
396+ dictTrace (SubclassDictionaryValue dict _ _) = dict
397+ dictTrace other = other
388
398
389-- |
399-- |
390-- Check all values in a list pairwise match a predicate
400-- Check all values in a list pairwise match a predicate