Closed
Description
Based on the failures in two Open CB projects:
- sangria-graphql/sangria https://scala3.westeurope.cloudapp.azure.com/job/buildCommunityProject/27128/
- sangria-graphql/sangria-relay https://scala3.westeurope.cloudapp.azure.com/job/buildCommunityProject/26601/
Sangria relies on type inference when defining Argument
types as they might have complex, tagged types. Due to the regression compiler needs hints about the result type. Otherwise it is not able to resolve it
Compiler version
3.3.0-RC1-bin-20221205-5cf8a58-NIGHTLY
Bisect points to 3d4275d
Minimized code
object tag {
type Tag[U]
opaque type Tagged[U] = Tag[U]
type @@[+T, U] = (T & Tagged[U]) | Null
}
import tag.*
trait FromInput[Val]
object FromInput {
trait CoercedScalaResult
implicit def optionInput[T](implicit ev: FromInput[T]): FromInput[Option[T]] = ???
implicit def coercedScalaInput[T]: FromInput[T @@ CoercedScalaResult] = ???
}
import FromInput.CoercedScalaResult
object schema {
trait InputType[+T] // This is critical! Making InputType invariant allows to compile
case class OptionInputType[T](ofType: InputType[T]) extends InputType[Option[T]]
class ScalarType[T] extends InputType[T @@ CoercedScalaResult]
implicit val IntType: ScalarType[Int] = ???
}
export schema.*
trait WithoutInputTypeTags[T] { type Res }
object WithoutInputTypeTags {
implicit def coercedArgTpe[T]: WithoutInputTypeTags[T @@ CoercedScalaResult] { type Res = T } = ???
implicit def coercedOptArgTpe[T]: WithoutInputTypeTags[Option[T @@ CoercedScalaResult]] { type Res = Option[T] } = ???
}
trait Argument[T]
object Argument {
def apply[T](argumentType: InputType[T])(implicit
fromInput: FromInput[T],
res: WithoutInputTypeTags[T]
): Argument[res.Res] = ???
}
@main def Test = {
// Does not compile
val optionalArgument = Argument(
argumentType = OptionInputType(IntType),
)
// This would compile
val hintedArg = Argument[Option[Int @@ CoercedScalaResult]](
argumentType = OptionInputType(IntType)
)
}
Output
[error] ./test.scala:41:3: Recursion limit exceeded.
[error] Maybe there is an illegal cyclic reference?
[error] If that's not the case, you could also try to increase the stacksize using the -Xss JVM option.
[error] For the unprocessed stack trace, compile with -Yno-decode-stacktraces.
[error] A recurring operation is (inner to outer):
[error]
[error] check fully defined T
[error] check fully defined T & tag.Tagged[FromInput.CoercedScalaResult]
[error] check fully defined T & tag.Tagged[FromInput.CoercedScalaResult]
[error] check fully defined Option[T & tag.Tagged[FromInput.CoercedScalaResult]]
[error] check fully defined Argument[Option[T & tag.Tagged[FromInput.CoercedScalaResult]]]
Expectation
Should compile