Skip to content

Commit 8a104fd

Browse files
authored
Fix incorrect caching with dependent method parameters (#21699)
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 ParamRefs.
2 parents bd3046b + c32e535 commit 8a104fd

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

+3
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ object Types extends TypeUtils {
144144
!t.isPermanentlyInstantiated || test(t.permanentInst, theAcc)
145145
case t: LazyRef =>
146146
!t.completed || test(t.ref, theAcc)
147+
case t: ParamRef =>
148+
(t: Type).mightBeProvisional = false // break cycles
149+
test(t.underlying, theAcc)
147150
case _ =>
148151
(if theAcc != null then theAcc else ProAcc()).foldOver(false, t)
149152
end if

tests/neg/i16842.check

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
-- Error: tests/neg/i16842.scala:24:7 ----------------------------------------------------------------------------------
2-
24 | Liter(SemanticArray[SemanticInt.type], x) // error
3-
| ^
4-
| invalid new prefix (dim: Int): SemanticArray[SemanticInt.type] cannot replace ty.type in type ty.T
1+
-- [E007] Type Mismatch Error: tests/neg/i16842.scala:24:8 -------------------------------------------------------------
2+
24 | Liter(SemanticArray[SemanticInt.type], x) // error // error
3+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
| Found: Int => SemanticArray[SemanticInt.type]
5+
| Required: SemanticArray[SemanticType]
6+
|
7+
| longer explanation available when compiling with `-explain`
8+
-- [E007] Type Mismatch Error: tests/neg/i16842.scala:24:41 ------------------------------------------------------------
9+
24 | Liter(SemanticArray[SemanticInt.type], x) // error // error
10+
| ^
11+
| Found: (x : List[Expr2[SemanticInt.type]])
12+
| Required: ty.T
13+
| Note that implicit conversions were not tried because the result of an implicit conversion
14+
| must be more specific than ty.T
15+
|
16+
| longer explanation available when compiling with `-explain`

tests/neg/i16842.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ def typecheckArrayLiter(
2121
a: ArrayLiter
2222
): Liter[SemanticArray[SemanticType]] = {
2323
val x: List[Expr2[SemanticInt.type]] = List()
24-
Liter(SemanticArray[SemanticInt.type], x) // error
24+
Liter(SemanticArray[SemanticInt.type], x) // error // error
2525
}

tests/pos/dep-poly-class.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait A:
2+
type B
3+
4+
class CCPoly[T <: A](a: T, b: a.B)
5+
6+
object Test:
7+
def test(): Unit =
8+
val aa: A { type B = Int } = new A { type B = Int }
9+
val x: CCPoly[aa.type] = CCPoly(aa, 1)

0 commit comments

Comments
 (0)