Skip to content

Commit 000de84

Browse files
committed
Reuse methods for prefix and owner
1 parent 4ff8bb1 commit 000de84

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ object TypeApplications {
4848
|| {
4949
val tparams = fn.typeParams
5050
val paramRefs = tparams.map(_.paramRef)
51-
val prefix = fn match { case fn: TypeRef => fn.prefix case _ => NoPrefix }
52-
val owner = fn match { case fn: TypeRef => fn.symbol.owner case _ => NoSymbol }
51+
val prefix = fn.normalizedPrefix
52+
val owner = fn.typeSymbol.maybeOwner
5353
tp.typeParams.corresponds(tparams) { (param1, param2) =>
54+
// see tests/neg/variances-constr.scala
55+
// its B parameter should have info <: Any, using class C as the owner
56+
// rather than info <: A, using class Inner2 as the owner
5457
param2.paramInfo.asSeenFrom(prefix, owner) frozen_<:< param1.paramInfo.substParams(tp, paramRefs)
5558
}
5659
}
@@ -303,7 +306,7 @@ class TypeApplications(val self: Type) extends AnyVal {
303306
def etaExpand(using Context): Type =
304307
val tparams = self.typeParams
305308
val resType = self.appliedTo(tparams.map(_.paramRef))
306-
self match
309+
self.dealias match
307310
case self: TypeRef if tparams.nonEmpty && self.symbol.isClass =>
308311
val owner = self.symbol.owner
309312
// Calling asSeenFrom on the type parameter infos is important

tests/neg/i7820.check

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
-- [E046] Cyclic Error: tests/neg/i7820.scala:1:23 ---------------------------------------------------------------------
2+
1 |trait A1 { type F[X <: F[_, _], Y] } // error: cyclic reference involving type F
3+
| ^
4+
| Cyclic reference involving type F
5+
|
6+
| Run with -explain-cyclic for more details.
7+
|
8+
| longer explanation available when compiling with `-explain`
9+
-- [E046] Cyclic Error: tests/neg/i7820.scala:2:23 ---------------------------------------------------------------------
10+
2 |trait A2 { type F[X <: F, Y] } // error: cyclic reference involving type F
11+
| ^
12+
| Cyclic reference involving type F
13+
|
14+
| Run with -explain-cyclic for more details.
15+
|
16+
| longer explanation available when compiling with `-explain`
17+
-- [E046] Cyclic Error: tests/neg/i7820.scala:3:23 ---------------------------------------------------------------------
18+
3 |trait A3 { type F[X >: F, Y] } // error: cyclic reference involving type F
19+
| ^
20+
| Cyclic reference involving type F
21+
|
22+
| Run with -explain-cyclic for more details.
23+
|
24+
| longer explanation available when compiling with `-explain`
25+
-- Warning: tests/neg/i7820.scala:1:25 ---------------------------------------------------------------------------------
26+
1 |trait A1 { type F[X <: F[_, _], Y] } // error: cyclic reference involving type F
27+
| ^
28+
| `_` is deprecated for wildcard arguments of types: use `?` instead
29+
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
30+
-- Warning: tests/neg/i7820.scala:1:28 ---------------------------------------------------------------------------------
31+
1 |trait A1 { type F[X <: F[_, _], Y] } // error: cyclic reference involving type F
32+
| ^
33+
| `_` is deprecated for wildcard arguments of types: use `?` instead
34+
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.

tests/neg/i7820.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
trait A1 { type F[X <: F[_, _], Y] } // error: cyclic reference involving type F
2-
trait A2 { type F[X <: F, Y] } // error: cyclic reference involving type F // error
3-
trait A3 { type F[X >: F, Y] } // error: cyclic reference involving type F // error
2+
trait A2 { type F[X <: F, Y] } // error: cyclic reference involving type F
3+
trait A3 { type F[X >: F, Y] } // error: cyclic reference involving type F

0 commit comments

Comments
 (0)