mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
Provide warning for defs that are used only in (mutual) recursion
This patch provides errors for defs that are used only in possibly-mutual recursion, and are not reachable outside of their recursive closures. For example: ``` test_report!( mutual_recursion_not_reached_nested, indoc!( r#" app "test" provides [main] to "./platform" main = f = \{} -> if Bool.true then "" else g {} g = \{} -> if Bool.true then "" else f {} "" "# ), @r###" ── DEFINITIONs ONLY USED IN RECURSION ──────────────────── /code/proj/Main.roc ─ These 2 definitions are only used in mutual recursion with themselves: 4│> f = \{} -> if Bool.true then "" else g {} 5│> g = \{} -> if Bool.true then "" else f {} If you don't intend to use or export any of them, they should all be removed! "### ); ```
This commit is contained in:
parent
1beb00f490
commit
0a807dc43e
8 changed files with 262 additions and 15 deletions
|
@ -376,6 +376,9 @@ pub fn canonicalize_module_defs<'a>(
|
|||
|
||||
// See if any of the new idents we defined went unused.
|
||||
// If any were unused and also not exposed, report it.
|
||||
//
|
||||
// We'll catch symbols that are only referenced due to (mutual) recursion later,
|
||||
// when sorting the defs.
|
||||
for (symbol, region) in symbols_introduced {
|
||||
if !output.references.has_type_or_value_lookup(symbol)
|
||||
&& !exposed_symbols.contains(&symbol)
|
||||
|
@ -427,8 +430,14 @@ pub fn canonicalize_module_defs<'a>(
|
|||
..Default::default()
|
||||
};
|
||||
|
||||
let (mut declarations, mut output) =
|
||||
crate::def::sort_can_defs_new(&mut scope, var_store, defs, new_output);
|
||||
let (mut declarations, mut output) = crate::def::sort_can_defs_new(
|
||||
&mut env,
|
||||
&mut scope,
|
||||
var_store,
|
||||
defs,
|
||||
new_output,
|
||||
exposed_symbols,
|
||||
);
|
||||
|
||||
debug_assert!(
|
||||
output.pending_derives.is_empty(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue