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

Reflection warnings on "+" operator #26

Open
darkleaf opened this issue Sep 12, 2019 · 3 comments
Open

Reflection warnings on "+" operator #26

darkleaf opened this issue Sep 12, 2019 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@darkleaf
Copy link
Contributor

operator.clj:149 recur arg for primitive local: sum is not matching primitive, had: Object, needed: long
Auto-boxing loop arg: sum

Is this patch correct?

(defoperator + [methods invoke]
  (loop [sum 0, [method & more] methods]
    ;;  (let [sum (long (+ (invoke method) sum))] 
    ;;             ^^^^
    (let [sum (+ (invoke method) sum)]
      (if (seq more)
        (recur sum more)
        sum))))
@darkleaf
Copy link
Contributor Author

May be it should be a double?

@camsaul
Copy link
Owner

camsaul commented Apr 23, 2020

I've noticed this, but am not sure what the best way to fix it is. It seems like there are use cases where all your implementations would return integers and other cases where all your implementations would return floating-point numbers. BigIntegers or Decimals are also possibilities, so we probably don't want to second-guess those cases and convert those to Doubles.

@camsaul camsaul added the help wanted Extra attention is needed label Apr 23, 2020
@glchapman
Copy link

glchapman commented Oct 19, 2021

A simple way to get a boxed primitive is to use identity, for example:

  (loop [sum (identity 0), [method & more] methods]

should make the warning go away.

EDIT: in this case, probably better to use Long/valueOf for boxing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants