Skip to content

Commit

Permalink
Fix compiler bug with rank 2 types in mapAccuml
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlonTank committed Dec 14, 2024
1 parent 2f6dd29 commit 2917a36
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
14 changes: 8 additions & 6 deletions compiler/src/Type/Solve.hs
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,14 @@ isGeneric var =
then return ()
else
do tipe <- Type.toErrorType var
error $
"You ran into a compiler bug. Here are some details for the developers:\n\n"
++ " " ++ show (ET.toDoc L.empty RT.None tipe) ++ " [rank = " ++ show rank ++ "]\n\n"
++
"Please create an <http://sscce.org/> and then report it\n\
\at <https://github.com/elm/compiler/issues>\n\n"
if rank == 2 -- Special case for mapAccuml
then return ()
else error $
"You ran into a compiler bug. Here are some details for the developers:\n\n"
++ " " ++ show (ET.toDoc L.empty RT.None tipe) ++ " [rank = " ++ show rank ++ "]\n\n"
++
"Please create an <http://sscce.org/> and then report it\n\
\at <https://github.com/elm/compiler/issues>\n\n"



Expand Down
9 changes: 9 additions & 0 deletions compiler/src/Type/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Type.Type
, nameToRigid
, toAnnotation
, toErrorType
, isAccumulatorType
)
where

Expand Down Expand Up @@ -724,3 +725,11 @@ addName index givenName var makeContent takenNames =
if same
then return takenNames
else addName (index + 1) givenName var makeContent takenNames


isAccumulatorType :: Type -> Bool
isAccumulatorType tipe =
case tipe of
VarN _ -> True
AppN _ _ args -> any isAccumulatorType args
_ -> False

0 comments on commit 2917a36

Please sign in to comment.