question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"+" method shadowed by any2stringadd

See original GitHub issue

Hi! Thanks for a wonderful library.

We’re hitting an interesting issue:

@newtype case class Demo(value: Int) {
  def +(another: Demo): Demo = ???
}

def demo(d: Demo) = d + d
                      ^ type mismatch;
 found   : (...).Demo
    (which expands to)  (...).Demo.Type
 required: String

If I just say d +, I get missing argument list for method + in class any2stringadd. As far as I could find out, that method gets special treatment and can’t be unimported.

I took a look at the implementation of newtypes and as far as I could tell methods from the class are moved to an implicit class next to it, to which a conversion called Demo.Ops$newtype is applied - when I apply it manually, or import it (import Demo._ or by exact name) it compiles as expected. I assume any2stringadd just has higher precedence because it’s imported.

Is there something scala-newtype can do to allow this name in methods on newtypes?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kubukozcommented, May 27, 2020

Okay, I actually hadn’t checked that (just extrapolated a bit from the newtype example, sorry!).

That works. But not on a newtype…

0reactions
carymrobbinscommented, Jun 13, 2020

I’m going to go ahead and close this, but if there are still unresolved issues, please re-open.

Read more comments on GitHub >

github_iconTop Results From Across the Web

scala - Shadow any2stringadd when implicitly converting Symbol ...
I don't like either solution. My question is, is there any other way to rephrase my program to convince scala to select my...
Read more >
any2stringadd implicit should be removed from Predef #194
There should at least be a way to turn this implicit off. ... What I do is shadow the definition of Predef.any2stringadd by...
Read more >
Scala Standard Library 2.13.6 - scala.Predef.any2stringadd
Injects String concatenation operator + to any classes. Annotations: @deprecated; Deprecated. (Since version 2.13.0) Implicit injection of + is deprecated.
Read more >
any2stringadd - scala.Predef.any2stringadd
Returns the runtime class representation of the object. Returns the runtime class representation of the object. returns. a class object corresponding to the ......
Read more >
Pull - fs2-core_2.11 0.9.5 javadoc
Allows acquiring elements from a stream in a resource safe way, ... O, R] to any2stringadd[Pull[F, O, R]] performed by method any2stringadd in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found