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

feature: warn if called in void context #8

Closed
dolmen opened this issue Oct 4, 2016 · 7 comments
Closed

feature: warn if called in void context #8

dolmen opened this issue Oct 4, 2016 · 7 comments

Comments

@dolmen
Copy link
Contributor

dolmen commented Oct 4, 2016

pushd is so magic that it is easy to forget to call it in scalar context (as the variable is normally not used in the rest of the scope).
It would be a helpful addition to check if pushd/tempd/preserve are called in void context (!defined wantarray) and warn.

@xdg
Copy link
Contributor

xdg commented Oct 4, 2016

Great idea. Want to send a patch? :-)

@dolmen
Copy link
Contributor Author

dolmen commented Oct 4, 2016

Want to send a patch? :-)

Yep.
Ideally the warn would happen only if warnings are enabled in the caller scope. Any idea on how to check that?

@xdg
Copy link
Contributor

xdg commented Oct 4, 2016

Probably with warnings::warn_if() but you'll need to choose a suitable category. From perldiag, the "useless" warnings appear to be in category "misc".

@dolmen
Copy link
Contributor Author

dolmen commented Oct 4, 2016

"Useless use of %s in void context" is in the void category. That's what I'll use.

@dolmen
Copy link
Contributor Author

dolmen commented Oct 4, 2016

Do you have any preference for a module to capture warnings in the testsuite? I can also directly hook $SIG{__WARN__} if you prefer...

@xdg
Copy link
Contributor

xdg commented Oct 4, 2016

Hook $SIG{__WARN__} please.

@xdg
Copy link
Contributor

xdg commented Oct 5, 2016

Fixed by #9

@xdg xdg closed this as completed Oct 5, 2016
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

No branches or pull requests

2 participants