Skip to content
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

Regression in type inference - critical for sangria-graphl ecosystem #16471

Closed
WojciechMazur opened this issue Dec 6, 2022 · 1 comment · Fixed by #16514
Closed

Regression in type inference - critical for sangria-graphl ecosystem #16471

WojciechMazur opened this issue Dec 6, 2022 · 1 comment · Fixed by #16514
Assignees
Labels
area:infer area:typer itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@WojciechMazur
Copy link
Contributor

WojciechMazur commented Dec 6, 2022

Based on the failures in two Open CB projects:

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

@WojciechMazur WojciechMazur added itype:bug area:typer regression This worked in a previous version but doesn't anymore area:infer labels Dec 6, 2022
@odersky
Copy link
Contributor

odersky commented Dec 7, 2022

In fact, the bisected commit was not the problem but some later commit in PR #16042 did have the same effect. However, that problem was fixed in #16353, which was merged 19 days ago.
The problem came back with 50eb0e9 from #16410, which was merged 6 days ago.
So we should revisit #16410.

@odersky odersky assigned smarter and unassigned odersky Dec 7, 2022
@Kordyjan Kordyjan added this to the 3.3.0-RC1 milestone Dec 12, 2022
smarter added a commit to dotty-staging/dotty that referenced this issue Dec 13, 2022
This regressed in 50eb0e9 when
`current.ensureNonCyclic` was incorrectly replaced by `validBoundsFor` which
operates on `this`, not `current`.

This isn't the first time we make this error (cf
a8641c5), maybe we should refactor
OrderingConstraint so that operations on `current` are done in the companion
object where `this` isn't accessible.

Fixes scala#16471.
smarter added a commit to dotty-staging/dotty that referenced this issue Dec 13, 2022
This regressed in 50eb0e9 when
`current.ensureNonCyclic` was incorrectly replaced by `validBoundsFor` which
operates on `this`, not `current`.

This isn't the first time we make this error (cf
a8641c5), maybe we should refactor
OrderingConstraint so that operations on `current` are done in the companion
object where `this` isn't accessible.

Fixes scala#16471.
smarter added a commit to dotty-staging/dotty that referenced this issue Dec 13, 2022
This regressed in 50eb0e9 when
`current.ensureNonCyclic` was incorrectly replaced by `validBoundsFor` which
operates on `this`, not `current`.

This isn't the first time we make this error (cf
a8641c5), maybe we should refactor
OrderingConstraint so that operations on `current` are done in the companion
object where `this` isn't accessible.

Fixes scala#16471.
smarter added a commit to dotty-staging/dotty that referenced this issue Dec 14, 2022
This regressed in 50eb0e9 when
`current.ensureNonCyclic` was incorrectly replaced by `validBoundsFor` which
operates on `this`, not `current`.

This isn't the first time we make this error (cf
a8641c5), maybe we should refactor
OrderingConstraint so that operations on `current` are done in the companion
object where `this` isn't accessible.

Fixes scala#16471. Note that the test case from this issue couldn't be added
because it fails `-Ycheck:typer`, but this was also the case before the
regression. This is now tracked by scala#16524.
odersky added a commit that referenced this issue Dec 14, 2022
This regressed in 50eb0e9 when
`current.ensureNonCyclic` was incorrectly replaced by `validBoundsFor`
which operates on `this`, not `current`.

This isn't the first time we make this error (cf
a8641c5), maybe we should refactor
OrderingConstraint so that operations on `current` are done in the
companion object where `this` isn't accessible.

Fixes #16471. Note that the test case from this issue couldn't be added
because it fails `-Ycheck:typer`, but this was also the case before the
regression. This is now tracked by #16524.
little-inferno pushed a commit to little-inferno/dotty that referenced this issue Jan 25, 2023
This regressed in 50eb0e9 when
`current.ensureNonCyclic` was incorrectly replaced by `validBoundsFor` which
operates on `this`, not `current`.

This isn't the first time we make this error (cf
a8641c5), maybe we should refactor
OrderingConstraint so that operations on `current` are done in the companion
object where `this` isn't accessible.

Fixes scala#16471. Note that the test case from this issue couldn't be added
because it fails `-Ycheck:typer`, but this was also the case before the
regression. This is now tracked by scala#16524.
@Kordyjan Kordyjan modified the milestones: 3.3.0-RC1, 3.3.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:infer area:typer itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants