Skip to content

value + is not a member of Int #23167

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

Open
scarf005 opened this issue May 15, 2025 · 3 comments
Open

value + is not a member of Int #23167

scarf005 opened this issue May 15, 2025 · 3 comments
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement

Comments

@scarf005
Copy link

Compiler version

3.7.0

Minimized example

(1, 2).map([Int] => (x: Int) => x + 1)

Output Error/Warning message

scala> (1, 2).map([Int] => (x: Int) => x + 1)
-- [E008] Not Found Error: --------------------------------------------------------------------------------------
1 |(1, 2).map([Int] => (x: Int) => x + 1)
  |                                ^^^
  |                        value + is not a member of Int, but could be made available as an extension method.
  |
  |                        One of the following imports might make progress towards fixing the problem:
  |
  |                          import scala.math.Fractional.Implicits.infixFractionalOps
  |                          import scala.math.Integral.Implicits.infixIntegralOps
  |                          import scala.math.Numeric.Implicits.infixNumericOps
  |
1 error found

Why this Error/Warning was not helpful

the error message value + is not a member of Int is very confusing because 1 + 1 = 2

Suggested improvement

probably same as #10082

@scarf005 scarf005 added itype:enhancement area:reporting Error reporting including formatting, implicit suggestions, etc stat:needs triage Every issue needs to have an "area" and "itype" label better-errors Issues concerned with improving confusing/unhelpful diagnostic messages labels May 15, 2025
@Gedochao Gedochao removed the stat:needs triage Every issue needs to have an "area" and "itype" label label May 15, 2025
@bishabosha
Copy link
Member

bishabosha commented May 15, 2025

so i was not sure if your intention here was for the function to work with scala.Int or to illustrate an error message that doesnt hint the user in the right direction.

If the first case then the error is because [Int] => (i: Int) => i + 1 means "create a generic function with a generic type parameter called Int (unrelated to scala.Int) and use the generic type parameter as the type of parameter i of the function"

possible solutions, perhaps in type errors we can hint if generic type parameters names shadow any other types visible from the scope?

@scarf005
Copy link
Author

sorry, lacked some context:
after reading https://discord.com/channels/632150470000902164/632150470000902166/1372495676637708390 i was testing how to map over a tuple (intuition: (1, 2).map(_ + 1) == (2, 3)), and stumbled upon this error message.

i remember scala error messages showing ABC is not equal to ABC²; foo.bar.ABC is not equal to baz.qux.ABC; maybe this one could use the same method.

@som-snytt
Copy link
Contributor

There is a proposal somewhere to run refchecks after erroring before refchecks.

It should also run -Wall checks.

In this case, the shadowing Int does not (yet) warn under -Wshadow:something-something.

-Wshadow:type-parameter-shadow

-- Warning: /home/amarki/snips/i23167.scala:4:6 --------------------------------
4 |def f[Int] = (x: Int) => ???
  |      ^^^
  |Type parameter Int for method f shadows the type defined by class Int in package scala
-- [E198] Unused Symbol Warning: /home/amarki/snips/i23167.scala:4:14 ----------
4 |def f[Int] = (x: Int) => ???
  |              ^
  |              unused explicit parameter
-- [E198] Unused Symbol Warning: /home/amarki/snips/i23167.scala:6:18 ----------
6 |def g = [Int] => (x: Int) => ???
  |                  ^
  |                  unused explicit parameter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement
Projects
None yet
Development

No branches or pull requests

4 participants