git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix #2252, instantiate types in array literals before unification (#2258)

* Fix #2252, instantiate types in array literals before unification * Use @garyb's test

commit2d6087d26d963d99b217ca1de1b18d827f1805b1 authorPhil Freeman <paf31@cantab.net> dateSun 31 Jul 2016, 16:15 (10 years ago) parent455848a
2 files changed+20−2
examples/passing/2252.purs+15 src/Language/PureScript/TypeChecker/Types.hs+5−2
examples/passing/2252.pursnew file+15
@@ -0,0 +1,15 @@
1+module Main where
2+
3+import Control.Monad.Eff.Console (log)
4+
5+data T a = T
6+
7+ti :: T Int
8+ti = T
9+
10+t :: forall a. T a
11+t = T
12+
13+xs = [ti, t, t]
14+
15+main = log "Done"
src/Language/PureScript/TypeChecker/Types.hs+5−2
@@ -245,8 +245,11 @@ infer' v@(Literal (BooleanLiteral _)) = return $ TypedValue True v tyBoolean
245245infer' (Literal (ArrayLiteral vals)) = do
246246 ts <- traverse infer vals
247247 els <- freshType
248− forM_ ts $ \(TypedValue _ _ t) -> unifyTypes els t
249− return $ TypedValue True (Literal (ArrayLiteral ts)) (TypeApp tyArray els)
248+ ts' <- forM ts $ \(TypedValue ch val t) -> do
249+ (val', t') <- instantiatePolyTypeWithUnknowns val t
250+ unifyTypes els t'
251+ return (TypedValue ch val' t')
252+ return $ TypedValue True (Literal (ArrayLiteral ts')) (TypeApp tyArray els)
250253infer' (Literal (ObjectLiteral ps)) = do
251254 ensureNoDuplicateProperties ps
252255 ts <- traverse (infer . snd) ps