Skip to content

Typer: Instability & Inconsistent Conformance Check Report #16950

Closed
@ftucky

Description

@ftucky

Edited to reflect code minimization findings, absent from the original submission.

Compiler version

3.2.0, 3.2.2, 3.3.0-RC2

Minimized code

object Foo:
  def bar(x:YOf[K]):Unit = ???
  bar(???)

trait K:
  type C
  sealed trait X:
    type CType <: YOf[C]
    def foo : K#Y =
      val x : CType = ???
      x

  sealed trait Y extends X

type YOf[+T] = K#Y { type M <: T }

https://scastie.scala-lang.org/8oKKJzCeRMK0Coc7uaGKCw

Output

Scala compiler reports failed type conformance check (`...but the comparison trace ended with false).
However, the trace itself ends with true.

13 |      x
   |      ^
   |      Found:    (x : X.this.CType)
   |      Required: a.K#Y
   |----------------------------------------------------------------------------
   | Explanation (enabled by `-explain`)
   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   |
   | Tree: x
   | I tried to show that
   |   (x : X.this.CType)
   | conforms to
   |   a.K#Y
   | but the comparison trace ended with `false`:
   |
   |   ==> (x : X.this.CType)  <:  a.K#Y
   |     ==> X.this.CType  <:  a.K#Y (left is approximated)
   |       ==> a.YOf[K.this.C]  <:  a.K#Y (left is approximated)
   |         ==> a.K#Y{M <: K.this.C}  <:  a.K#Y (left is approximated)
   |           ==> a.K#Y  <:  a.K#Y (left is approximated)
   |           <== a.K#Y  <:  a.K#Y (left is approximated) = true
   |         <== a.K#Y{M <: K.this.C}  <:  a.K#Y (left is approximated) = true
   |       <== a.YOf[K.this.C]  <:  a.K#Y (left is approximated) = true
   |     <== X.this.CType  <:  a.K#Y (left is approximated) = true
   |   <== (x : X.this.CType)  <:  a.K#Y = true
   |
   | The tests were made under the empty constraint
    ----------------------------------------------------------------------------

Expectation

Either

  • the conformance check to pass, or
  • the trace to end with = false

Observations

  • Failure depends on the positions of object Foo and trait K. https://scastie.scala-lang.org/UqVDSBaURW22P6Qsnw4ZgQ compiles correctly.
  • When object Foo is not present in the file, the file compiles correctly by itself.
  • However, when object Foo is present in another file, failure becomes dependent on the relative order of both files compilation, with a race condition.
  • Under sbt the race creates a memory effect: if a former compilation run left a valid tasty for trait K, issue disappears as well. ( sometimes until sbt clean, sometimes not )

Any clue about what could cause the inconsistency in the report ?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions