Skip to content

Cannot translate usage of wildcard type from Scala 2 #9897

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

Closed
oyvindberg opened this issue Sep 27, 2020 · 1 comment
Closed

Cannot translate usage of wildcard type from Scala 2 #9897

oyvindberg opened this issue Sep 27, 2020 · 1 comment

Comments

@oyvindberg
Copy link

Minimized code

type WatchHandler[T] = Function2[/* val */ T, /* oldVal */ T, scala.Unit]
val handlers: Seq[WatchHandler[_]] = Nil

Output

unreducible application of higher-kinded type [T] =>> (T, T) => Unit to wildcard arguments

Expectation

In Scala 2 this compiles. I tried replacing with ? instead, but got the same error.

@smarter
Copy link
Member

smarter commented Sep 27, 2020

This is intentionally not supported: we only allow wildcards on class types (because anything else would be equivalent to existential types which we don't support), some alternatives you could use:

  • wrap the type in a class: class WatchHandler[T](f: Function2[T, T, scala.Unit]
  • extend Function2: trait WatchHandler[T] extends Function2[T, T, scala.Unit]
  • not sure if it would make sense here, but one could use the new-in-dotty polymorphic function types: val handlers: Seq[[T] => () => WatchHandler[T]] = Nil, cf [Proof of concept] Polymorphic function types #4672

@smarter smarter closed this as completed Sep 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants