Skip to content

Commit

Permalink
Fix incorrect caching with path-dependent types
Browse files Browse the repository at this point in the history
The added test case used to fail Ycheck:typer with the seemingly identicals:

    Found:    (a: (aa : A{type B = Int}), b: a.B): CCPoly[(aa : A{type B = Int})]
    Required: (a: (aa : A{type B = Int}), b: a.B): CCPoly[(aa : A{type B = Int})]

In fact one of the `aa` is a a TypeVar instantiated to `A {type B = Int }`. The
MethodType comparison failed the signature check because the `a.B` where `a` is
backed by a type variable had a stale signature cached.

Fixed by changing `isProvisional` to traverse BoundTypes (`a` is a
`TermParamRef` here).
  • Loading branch information
smarter committed Oct 3, 2024
1 parent c332766 commit a09b8a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ object Types extends TypeUtils {
!t.isPermanentlyInstantiated || test(t.permanentInst, theAcc)
case t: LazyRef =>
!t.completed || test(t.ref, theAcc)
case t: BoundType =>
(t: Type).mightBeProvisional = false // break cycles
test(t.underlying, theAcc)
case _ =>
(if theAcc != null then theAcc else ProAcc()).foldOver(false, t)
end if
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/dep-poly-class.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
trait A:
type B

class CCPoly[T <: A](a: T, b: a.B)

object Test:
def test(): Unit =
val aa: A { type B = Int } = new A { type B = Int }
val x: CCPoly[aa.type] = CCPoly(aa, 1)

0 comments on commit a09b8a3

Please sign in to comment.