Skip to content

Resolve how to handle errors of closures taking by-name arguments with wildcard types #16789

Closed
@WojciechMazur

Description

@WojciechMazur

Compiler version

3.3.1-RC1-bin-20230129-b8ad7b1-NIGHTLY

Related to closures with by-name arguments change b439deb

Durated the meeting it was mentioned, that maybe we should treat Java types differently

Minimized code

Based on the results of OpenCB build (links to build logs below)

Case 1

Based on compilation issue in zio/zio-http

def shutdownGracefully(): java.util.concurrent.Future[_] = ???

def executedWildcard(jFuture: => java.util.concurrent.Future[_]): Unit = ???
def executedGeneric[A](jFuture: => java.util.concurrent.Future[A]): Unit = ???

def works = executedWildcard(shutdownGracefully())
def fails = executedGeneric(shutdownGracefully())

Output

-- Error: /workspace/bisect/test.scala:7:27 ------------------------------------
7 |def fail = executedGeneric(shutdownGracefully())
  |                           ^^^^^^^^^^^^^^^^^^^^
  |argument for by-name parameter contains capture conversion skolem types:
  |java.util.concurrent.Future[?1.CAP]
  |
  |where:    ?1 is an unknown value of type scala.runtime.TypeBox[Nothing, Object]

Case 2

When used with Specs2 4.x in tests of reactivemongo/reactivemongo-bson and playframework/play-ws

//> using lib  "org.specs2::specs2-matcher-extra:4.19.0"

class Foo

final class RegressionTest extends org.specs2.mutable.Specification {
  val cls = classOf[Foo]
  val instance = new Foo()
  val works = cls must_== cls
  val fails = instance.getClass must_== cls
  val failsCase2 = instance.getClass() must not(throwA[ClassNotFoundException])
}

Output

[error] ./test.scala:10:20: value must is not a member of Class[?1.CAP].
[error] An extension method was tried, but could not be fully constructed:
[error] 
[error]     this.theValue[T](this.instance.getClass[Foo]().$asInstanceOf[Class[?1.CAP]])
[error] 
[error] where:    ?1 is an unknown value of type scala.runtime.TypeBox[Nothing, Foo]
[error]   val failsCase2 = instance.getClass() must not(throwA[ClassNotFoundException])
[error]   

Expectation

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions