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
Context-bound on unnamed type parameter becomes Any #11425
Comments
Not limited to classes:
The relevant section of the spec is https://www.scala-lang.org/files/archive/spec/2.11/07-implicits.html#context-bounds-and-view-bounds. It does not mention wildcards explicitly but the current behavior violates this part:
|
Let met try my best @smarter impersonation: "Works in Dotty" Well, sort of. Dotty doesn't allow wildcard type parameters anymore so the problem doesn't come up in the first place. If that's the way forward then we should do the same in 2.14. |
I believe so, I'd say the fact that wildcards can be used in type parameter position is just an accident of the parser implementation and not a real feature. |
Is there a problem is supporting this pattern? On the other side of the equation: can we find a good reason why to support this? Maybe we should run the community build against the removal to see how/why it's used. |
It's not intended to be a wildcard, but an unnamed type parameter. I think that's that the bug is. |
Just another use of |
The syntax is officially documented in the spec though. Just not the semantics, which shouldn't be a problem if they are simply unnamed type parameters. I also assumed that's what they are. In this case it should be easy to fix by synthesizing a name very early (parsers or namers) before the context bound desugaring happens. Good reasons for disallowing this syntax:
|
OTOH it is very similar to the use of
|
If we don't drop unnamed type parameters, we might want to lift the restriction on naming multiple proper type parameters scala> class G[_]
defined class G
scala> class H[_]
defined class H
scala> class A[_: G, _: H]
<console>:13: error: _ is already defined as type _
class A[_: G, _: H]
^ like you can for the parameters of a type constructor: scala> class F[_[_, _]]
defined class F
It would be nice to be able to name a parameter 15:20:13 $ sc -Ywarn-unused
Welcome to Scala 2.12.8 (OpenJDK 64-Bit Server VM, Java 11.0.2).
Type in expressions for evaluation. Or try :help.
scala> class A { def foo(x: Int) = () }; final class B extends A { override def foo(x: Int) = println(x) }
<console>:11: warning: parameter value x in method foo is never used
class A { def foo(x: Int) = () }; final class B extends A { override def foo(x: Int) = println(x) }
^
defined class A
defined class B |
Please no, no extra meaning for |
I wouldn't classify it as extra. It's the same meaning that already exists: the parameter is being (un)named |
You can already name one parameter
but it may not be a great idea. The better escape hatch is:
There is already a ticket for multiple type params named |
The text was updated successfully, but these errors were encountered: