Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Remove any2stringadd. #54

Closed
markhibberd opened this issue Sep 22, 2014 · 12 comments
Closed

Remove any2stringadd. #54

markhibberd opened this issue Sep 22, 2014 · 12 comments
Milestone

Comments

@markhibberd
Copy link

Following on from a related thread Paul has started this here https://github.com/paulp/policy/commit/d5c06772d

How feasible it is to support from behind a flag may be questionable - but this would be a big win if it can be done.

@ijuma
Copy link

ijuma commented Sep 22, 2014

This would be cool indeed.

@non
Copy link

non commented Sep 22, 2014

I had an idea of putting in a -Z flag that basically detects these sorts of usages of + (and makes them errors). This way new projects could avoid producing this kind of code, but the old projects would still work. Sort of like a built-in wart-remover, but without having to use ambiguous implicits to do it (and presumably with more specific error messages).

What do you think? The other alternative is to do something similar to what Paul did with Policy recently and modify the stdlib/compiler. I don't see a clear way for us to do that without drastically revising our compatibility guarantees.

@puffnfresh
Copy link

This was some of the motivation for #26 (any2stringadd is just an implicit in Predef) - sadly my PR misses a case and so doesn't give a nice error.

@paulp
Copy link

paulp commented Sep 22, 2014

@puffnfresh You know the implicit never kicks on expressions like 1 + "bob" because a (String)String method has been synthetically added to Int/Long/etc, yes? See paulp/policy@4bb74b2bb .

@puffnfresh
Copy link

Also, -Yno-predef is already a valid solution to this problem. I think we should also focus on making -Yno-imports a sensible thing to use.

@puffnfresh
Copy link

@paulp I am sadly very aware of that.

@non
Copy link

non commented Sep 22, 2014

Independent of -Yno-xyz solutions, we would need something else to disable the methods on Int &c. I'll try to prepare a flag-based branch to see how it feels.

@puffnfresh
Copy link

@non absolutely. That'd be great.

@puffnfresh puffnfresh added the bug label Sep 25, 2014
@puffnfresh
Copy link

I updated #32 to fix the problem with my implicitAmbiguous annotation. Now this code:

object Nope {
  @annotation.implicitAmbiguous("any2string is disabled")
  implicit def any2stringaddamb1[A](self: A): any2stringadd[A] = ???

  List(1, 2, 3) + "two"
}

Gives this:

/tmp/Nope.scala:5: error: any2string is disabled
  List(1, 2, 3) + "two"
      ^

Which makes me pretty happy.

🍰

@propensive
Copy link

Nice! Horrible use case, though... ;)

@milessabin
Copy link
Member

To resurrect this issue, please rework it as an issue/PR against Lightbend Scala (ie. scala/scala).

@milessabin milessabin added this to the Parked milestone Aug 12, 2016
@SethTisue
Copy link
Member

SethTisue commented Aug 12, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants