mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-09-17 14:47:21 +03:00
Merge pull request #262 from HigherOrderCO/bug/sc-510/unused-definition-warning-triggered-on-matched
[sc-510] Unused definition warning triggered on matched constructors when scott encoding is used
This commit is contained in:
commit
d1bbc40146
@ -38,6 +38,14 @@ impl Ctx<'_> {
|
|||||||
self.book.find_used_definitions(&def.rule().body, Used::Main, &mut used, adt_encoding);
|
self.book.find_used_definitions(&def.rule().body, Used::Main, &mut used, adt_encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let AdtEncoding::Scott = adt_encoding {
|
||||||
|
for (def_name, def) in &self.book.defs {
|
||||||
|
if !def.builtin && self.book.ctrs.get(def_name).is_some() {
|
||||||
|
used.insert(def_name.clone(), Used::Adt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Even if we don't prune all the defs, we need check what built-ins are accessible through user code
|
// Even if we don't prune all the defs, we need check what built-ins are accessible through user code
|
||||||
if !prune_all {
|
if !prune_all {
|
||||||
for (def_name, def) in &self.book.defs {
|
for (def_name, def) in &self.book.defs {
|
||||||
|
@ -451,3 +451,16 @@ fn examples() -> Result<(), Diagnostics> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn scott_triggers_unused() {
|
||||||
|
run_golden_test_dir(function_name!(), &|code, path| {
|
||||||
|
let mut book = do_parse_book(code, path)?;
|
||||||
|
let mut opts = CompileOpts::default_strict();
|
||||||
|
opts.adt_encoding = AdtEncoding::Scott;
|
||||||
|
let diagnostics_cfg =
|
||||||
|
DiagnosticsConfig { unused_definition: Severity::Error, ..DiagnosticsConfig::default_strict() };
|
||||||
|
let res = compile_book(&mut book, opts, diagnostics_cfg, None)?;
|
||||||
|
Ok(format!("{}{}", res.diagnostics, res.core_book))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
13
tests/golden_tests/scott_triggers_unused/test.hvm
Normal file
13
tests/golden_tests/scott_triggers_unused/test.hvm
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// The test below should not trigger this warning:
|
||||||
|
//
|
||||||
|
// In definition 'f':
|
||||||
|
// Definition is unused.
|
||||||
|
// In definition 't':
|
||||||
|
// Definition is unused.
|
||||||
|
//
|
||||||
|
// This was happening because the prune algorithm was just collecting constructors
|
||||||
|
// by searching for tags.
|
||||||
|
|
||||||
|
data bool = t | f
|
||||||
|
|
||||||
|
main = @b match b { t: 0; f: 1}
|
9
tests/snapshots/scott_triggers_unused__test.hvm.snap
Normal file
9
tests/snapshots/scott_triggers_unused__test.hvm.snap
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
source: tests/golden_tests.rs
|
||||||
|
input_file: tests/golden_tests/scott_triggers_unused/test.hvm
|
||||||
|
---
|
||||||
|
@f = (* (a a))
|
||||||
|
|
||||||
|
@main = ((#0 (#1 a)) a)
|
||||||
|
|
||||||
|
@t = (a (* a))
|
Loading…
Reference in New Issue
Block a user