compiler
compiler copied to clipboard
Fix compiler bug with rank 2 types in mapAccuml
This PR fixes a compiler bug that occurs when using mapAccuml with explicit type annotations. The bug manifested as a compiler crash with the message "x [rank = 2]" followed by "thread blocked indefinitely in an MVar operation".
The issue was that the compiler was incorrectly treating rank 2 type variables as invalid during generalization. These rank 2 variables are actually valid and necessary for higher-order functions like mapAccuml.
The fix modifies the isGeneric function to specifically allow rank 2 variables, which enables proper type inference for mapAccuml and similar functions.
Test case that previously crashed but now works properly:
func =
List.Extra.mapAccuml
(\acc x ->
let
newAcc = acc + 1
result = x + acc
in
( newAcc, result )
)
0
[1, 2, 3]
Unfortunately, it (hot)fixes the problem but there surely are some side-effects
Thanks for suggesting these code changes. To set expectations:
- Pull requests are reviewed in batches, so it can take some time to get a response.
- Smaller pull requests are easier to review. To fix nine typos, nine specific issues will always go faster than one big one. Learn why here.
- Reviewers may not know as much as you about certain situations, so add links to supporting evidence for important claims, especially regarding standards for CSS, HTTP, URI, etc.
Finally, please be patient with the core team. They are trying their best with limited resources.