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 variable check #864

Merged
merged 6 commits into from
Apr 4, 2023
Merged

Add unused variable check #864

merged 6 commits into from
Apr 4, 2023

Conversation

eliaslfox
Copy link
Collaborator

@eliaslfox eliaslfox commented Apr 4, 2023

Add warnings for unused variables:

(coalton-toplevel
  (define (f x) 5))
; caught COMMON-LISP:STYLE-WARNING:
;   warn: Unused variable
;     --> /private/var/tmp/slimedunOe0:2:13
;      |
;    2 |    (define (f x) 5))
;      |               ^ variable defined here

Variables can be marked as intentionally used by prefixing them with _. If an intentionally ignored variable is used, then a warning is generated:

(coalton-toplevel
  (define (f _x) _x))
;   warn: Use of ignored variable
;     --> /private/var/tmp/slimeQxQzkn:2:17
;      |
;    2 |    (define (f _x) _x))
;      |               -- definition here
;      |                   ^^ first usage here

Fixes #12

@eliaslfox eliaslfox marked this pull request as draft April 4, 2023 00:28
@stylewarning
Copy link
Member

FWIW, I've enjoyed the distinction of IGNORE and IGNORABLE in CL declarations, mostly for macro-generated code. But I do like the _x convention for most practical uses of ignoring a variable.

@gefjon
Copy link
Collaborator

gefjon commented Apr 4, 2023

But I do like the _x convention for most practical uses of ignoring a variable.

I'm a fan of Rust's using _ (the underscore with nothing after) as equivalent to CL's ignore, and _foo (an underscore with any valid identifier after) as ignorable.

@eliaslfox
Copy link
Collaborator Author

I'm a fan of Rust's using _ (the underscore with nothing after) as equivalent to CL's ignore, and _foo (an underscore with any valid identifier after) as ignorable.

I like this. I'll update this pr to make _foo equivalent to ignorable. Underscore bindings will be part of argument pattern matching (now tracked at #865).

@eliaslfox eliaslfox force-pushed the unused-variables branch 2 times, most recently from d50d993 to be8e5a7 Compare April 4, 2023 21:29
@colescott colescott marked this pull request as ready for review April 4, 2023 23:05
@eliaslfox eliaslfox enabled auto-merge (rebase) April 4, 2023 23:41
@eliaslfox eliaslfox merged commit 0d8307b into main Apr 4, 2023
@eliaslfox eliaslfox deleted the unused-variables branch April 4, 2023 23:45
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.

Add unused variable warning
4 participants