Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add _unused names #45

Merged
merged 3 commits into from
Apr 30, 2022
Merged

Add _unused names #45

merged 3 commits into from
Apr 30, 2022

Conversation

jmackie
Copy link
Member

@jmackie jmackie commented Apr 29, 2022

Currently, any unused value binders raise a warning. For example:

⚠ unused function binder
╭─[golden:1:1]
1 │ module Test exports (..);
2 │
3 │ always_five = (ignore) -> 5;
· ───┬──
· ╰── this isn't used
╰────

⚠ unused patter binder
╭─[golden:4:1]
4 │
5 │ not_used = (o: Option(a)): Float ->
6 │ match o with
7 │ | Some(a) -> 5.0
· ┬
· ╰── this isn't used
8 │ | None -> 5.0;
╰────

⚠ unused effect binder
╭─[golden:5:1]
5 │ };
6 │
7 │ greet : Effect(Unit) = do {
8 │ name <- get_name;
· ──┬─
· ╰── this isn't used
9 │ return unit
10 │ };
╰────

Clearly there are legitimate reasons to ignore a binding, so there needs to be a way to suppress these warnings. Most languages (and/or linters) that I'm aware of handle this by prefixing unused variables with a _.

However this is generally just a convention, as variables marked as unused (by a leading underscore) can usually still be referenced. And I'm not the only one who would prefer it if this convention was enforced by the compiler:

rust-lang/rust#3423
golang/go#39118

Ditto will enforce this by not treating _unused variables as valid expressions. In this PR this is enforced at the parser level, but that might change in future in the interest of more helpful error messages...

Note that this PR doesn't extend Effect::Bind with unused binders, that will be implemented as part of #46.

@jmackie jmackie marked this pull request as ready for review April 30, 2022 14:00
@codecov
Copy link

codecov bot commented Apr 30, 2022

Codecov Report

Merging #45 (6b84a25) into main (53a0eb4) will increase coverage by 0.02%.
The diff coverage is 85.10%.

@@            Coverage Diff             @@
##             main      #45      +/-   ##
==========================================
+ Coverage   77.23%   77.26%   +0.02%     
==========================================
  Files         109      109              
  Lines        6836     6914      +78     
==========================================
+ Hits         5280     5342      +62     
- Misses       1556     1572      +16     
Impacted Files Coverage Δ
...ates/ditto-checker/src/typechecker/substitution.rs 94.11% <ø> (ø)
crates/ditto-cst/src/name.rs 100.00% <ø> (ø)
crates/ditto-fmt/src/has_comments.rs 45.49% <42.85%> (-0.18%) ⬇️
crates/ditto-ast/src/expression.rs 83.33% <50.00%> (-2.67%) ⬇️
crates/ditto-ast/src/name.rs 77.77% <50.00%> (-2.23%) ⬇️
crates/ditto-fmt/src/expression.rs 98.86% <71.42%> (-0.76%) ⬇️
crates/ditto-cst/src/parser/expression.rs 99.59% <91.66%> (-0.41%) ⬇️
...ditto-checker/src/module/value_declarations/mod.rs 99.20% <100.00%> (+<0.01%) ⬆️
crates/ditto-checker/src/typechecker/mod.rs 96.26% <100.00%> (-0.15%) ⬇️
crates/ditto-checker/src/typechecker/pre_ast.rs 96.77% <100.00%> (+0.10%) ⬆️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 53a0eb4...6b84a25. Read the comment docs.

@jmackie jmackie merged commit a74afcb into main Apr 30, 2022
@jmackie jmackie deleted the init-unused-names branch April 30, 2022 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant