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

Avoiding warning: possibly useless use of + in void context #151

Open
mrkn opened this issue Jan 18, 2020 · 1 comment
Open

Avoiding warning: possibly useless use of + in void context #151

mrkn opened this issue Jan 18, 2020 · 1 comment

Comments

@mrkn
Copy link
Contributor

mrkn commented Jan 18, 2020

Our inplace idiom occurs warning like warning: possibly useless use of + in void context.
To avoid such warnings, how do you think defining inplace=?
With this method, we can write ary.inplace += 10, which don't occur such warnings.

$ cat -n inplace.rb
     1  require 'numo/narray'
     2
     3  class Numo::NArray
     4    # Dummy definition for PoC
     5    def inplace=(other)
     6      self
     7    end
     8  end
     9
    10  a = Numo::DFloat[1, 2, 3, 4, 5]
    11  a.inplace + 10   # this involves a warning
    12  a.inplace += 20  # this doesn't involve a warning
$ ruby -w inplace.rb
inplace.rb:11: warning: possibly useless use of + in void context
@masa16
Copy link
Member

masa16 commented Jan 20, 2020

This idea seems a good workaround, but it is not applicable to more complex expressions like

a.inplace * 2 + 1

Hmm...

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