Description
Compiler version
3.2.1 and 3.2.2-RC1
Minimized code
Runnable: https://scastie.scala-lang.org/WNexehduQzOT4XJ2XfUB7Q
import scala.compiletime.summonInline
case class TypeDesc[T](tpe: String)
object TypeDesc {
given TypeDesc[Nothing] = TypeDesc("Nothing")
given TypeDesc[String] = TypeDesc("String")
given TypeDesc[Int] = TypeDesc("Int")
}
def exampleFn(s: String, i: Int): Unit = ()
inline def argumentTypesOf[R](fun: (?, ?) => R): (TypeDesc[?], TypeDesc[?]) = {
inline fun match {
case x: ((a, b) => R) =>
(summonInline[TypeDesc[a]], summonInline[TypeDesc[b]])
}
}
inline def argumentTypesOfNoWildCard[A, B, R](fun: (A, B) => R): (TypeDesc[?], TypeDesc[?]) = argumentTypesOf(fun)
inline def argumentTypesOfAllWildCard(fun: (?, ?) => ?): (TypeDesc[?], TypeDesc[?]) = argumentTypesOf(fun)
@main def main: Unit = {
println(argumentTypesOf(exampleFn)) // good
println(argumentTypesOf(exampleFn(_, _))) // bad
println(argumentTypesOfNoWildCard(exampleFn(_, _))) // good
println(argumentTypesOfAllWildCard(exampleFn)) // bad, even without explicit placeholders
}
Output
(TypeDesc(String),TypeDesc(Int))
(TypeDesc(Nothing),TypeDesc(Nothing))
(TypeDesc(String),TypeDesc(Int))
(TypeDesc(Nothing),TypeDesc(Nothing))
Expectation
(TypeDesc(String),TypeDesc(Int))
(TypeDesc(String),TypeDesc(Int))
(TypeDesc(String),TypeDesc(Int))
(TypeDesc(String),TypeDesc(Int))
Expected there to be no difference between exampleFn
and exampleFn(_, _)
form in type inference in general and when calling argumentTypesOf
.
Expected all variants of argumentTypesOf* to not infer Nothing regardless of using wildcards anywhere in the parameter type.
This code is a minimized version of real library code in https://github.com/izumi/izumi which we're trying to port to Scala 3