on master help sign in
Have a more straight-forward crash for certain type inference algorithm issues
f678e11Evan Czaplicki
src/Type/Solve.hs+14−6
@@ -208,12 +208,12 @@ allDistinct vars =
208 do desc <- liftIO $ UF.descriptor var
208 do desc <- liftIO $ UF.descriptor var
209 case structure desc of
209 case structure desc of
210 Just _ ->
210 Just _ ->
211− TS.addError (error "Cannot generalize something that is not a type variable.") undefined
211+ crash "Cannot generalize something that is not a type variable."
212
212
213 Nothing ->
213 Nothing ->
214− do when (mark desc == seen) $
214+ if mark desc == seen
215− TS.addError (error "Duplicate variable during generalization.") undefined
215+ then crash "Duplicate variable during generalization."
216− liftIO $ UF.setDescriptor var (desc { mark = seen })
216+ else liftIO (UF.setDescriptor var (desc { mark = seen }))
217
217
218
218
219-- Check that a variable has rank == noRank, meaning that it can be generalized.
219-- Check that a variable has rank == noRank, meaning that it can be generalized.
@@ -222,8 +222,16 @@ isGeneric var =
222 do desc <- liftIO $ UF.descriptor var
222 do desc <- liftIO $ UF.descriptor var
223 if rank desc == noRank
223 if rank desc == noRank
224 then return ()
224 then return ()
225− else
226− TS.addError (error "Unable to generalize a type variable. It is not unranked.") undefined
225+ else crash "Unable to generalize a type variable. It is not unranked."
226+
227+
228+crash :: String -> a
229+crash msg =
230+ error $
231+ "It looks like something went wrong with the type inference algorithm.\n"
232+ ++ msg ++ "\n"
233+ ++ "Please create a minimal example that triggers this problem and report it to\n"
234+ ++ "<https://github.com/elm-lang/elm-compiler/issues>"
227
235
228
236
229occurs :: (String, Variable) -> StateT TS.SolverState IO ()
237occurs :: (String, Variable) -> StateT TS.SolverState IO ()