Make sure self-recursive checks only happen after typechecking

Programs like

```
after : ({} -> a), ({} -> b) -> ({} -> b)

fx = after (\{} -> {}) \{} -> if Bool.true then fx {} else {}
```

are legal because they always decay to functions, even if they may not
look like functions syntactically. Rather than using a syntactic check
to check for illegally-recursive functions, we should only perform such
checks after we know the types of values.

Closes #4291
This commit is contained in:
Ayaz Hafiz 2022-10-11 12:58:05 -05:00
parent 99ad019d75
commit ecab8fa25a
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
4 changed files with 74 additions and 80 deletions

View file

@ -422,7 +422,7 @@ pub fn canonicalize_module_defs<'a>(
};
let (mut declarations, mut output) =
crate::def::sort_can_defs_new(&mut env, &mut scope, var_store, defs, new_output);
crate::def::sort_can_defs_new(&mut scope, var_store, defs, new_output);
debug_assert!(
output.pending_derives.is_empty(),