Fix bug in unifying records

This was leading us to have an infinitely-recursive type, which eventually causes layout to stack-overflow

Fixes #4739
This commit is contained in:
Joshua Warner 2022-12-15 19:12:12 -08:00
parent faaa466c70
commit 174f7d5e4d
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
5 changed files with 191 additions and 13 deletions

View file

@ -1530,6 +1530,34 @@ fn encode_derived_record() {
)
}
#[mono_test(no_check)]
fn choose_correct_recursion_var_under_record() {
indoc!(
r#"
Parser : [
Specialize Parser,
Record (List {parser: Parser}),
]
printCombinatorParser : Parser -> Str
printCombinatorParser = \parser ->
when parser is
Specialize p ->
printed = printCombinatorParser p
if Bool.false then printed else "foo"
Record fields ->
fields
|> List.map \f ->
printed = printCombinatorParser f.parser
if Bool.false then printed else "foo"
|> List.first
|> Result.withDefault ("foo")
printCombinatorParser (Record [])
"#
)
}
#[mono_test]
fn tail_call_elimination() {
indoc!(