Skip to content

Commit

Permalink
Reuse methods for prefix and owner
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Feb 24, 2024
1 parent 4ff8bb1 commit c9220c2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
9 changes: 6 additions & 3 deletions compiler/src/dotty/tools/dotc/core/TypeApplications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ object TypeApplications {
|| {
val tparams = fn.typeParams
val paramRefs = tparams.map(_.paramRef)
val prefix = fn match { case fn: TypeRef => fn.prefix case _ => NoPrefix }
val owner = fn match { case fn: TypeRef => fn.symbol.owner case _ => NoSymbol }
val prefix = fn.normalizedPrefix
val owner = fn.typeSymbol.maybeOwner
tp.typeParams.corresponds(tparams) { (param1, param2) =>
// see tests/neg/variances-constr.scala
// its B parameter should have info <: Any, using class C as the owner
// rather than info <: A, using class Inner2 as the owner
param2.paramInfo.asSeenFrom(prefix, owner) frozen_<:< param1.paramInfo.substParams(tp, paramRefs)
}
}
Expand Down Expand Up @@ -303,7 +306,7 @@ class TypeApplications(val self: Type) extends AnyVal {
def etaExpand(using Context): Type =
val tparams = self.typeParams
val resType = self.appliedTo(tparams.map(_.paramRef))
self match
self.dealias match
case self: TypeRef if tparams.nonEmpty && self.symbol.isClass =>
val owner = self.symbol.owner
// Calling asSeenFrom on the type parameter infos is important
Expand Down
34 changes: 34 additions & 0 deletions tests/neg/i7820.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- [E046] Cyclic Error: tests/neg/i7820.scala:1:23 ---------------------------------------------------------------------
1 |trait A1 { type F[X <: F[_, _], Y] } // error: cyclic reference involving type F
| ^
| Cyclic reference involving type F
|
| Run with -explain-cyclic for more details.
|
| longer explanation available when compiling with `-explain`
-- [E046] Cyclic Error: tests/neg/i7820.scala:2:23 ---------------------------------------------------------------------
2 |trait A2 { type F[X <: F, Y] } // error: cyclic reference involving type F
| ^
| Cyclic reference involving type F
|
| Run with -explain-cyclic for more details.
|
| longer explanation available when compiling with `-explain`
-- [E046] Cyclic Error: tests/neg/i7820.scala:3:23 ---------------------------------------------------------------------
3 |trait A3 { type F[X >: F, Y] } // error: cyclic reference involving type F
| ^
| Cyclic reference involving type F
|
| Run with -explain-cyclic for more details.
|
| longer explanation available when compiling with `-explain`
-- Warning: tests/neg/i7820.scala:1:25 ---------------------------------------------------------------------------------
1 |trait A1 { type F[X <: F[_, _], Y] } // error: cyclic reference involving type F
| ^
| `_` is deprecated for wildcard arguments of types: use `?` instead
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
-- Warning: tests/neg/i7820.scala:1:28 ---------------------------------------------------------------------------------
1 |trait A1 { type F[X <: F[_, _], Y] } // error: cyclic reference involving type F
| ^
| `_` is deprecated for wildcard arguments of types: use `?` instead
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
4 changes: 2 additions & 2 deletions tests/neg/i7820.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
trait A1 { type F[X <: F[_, _], Y] } // error: cyclic reference involving type F
trait A2 { type F[X <: F, Y] } // error: cyclic reference involving type F // error
trait A3 { type F[X >: F, Y] } // error: cyclic reference involving type F // error
trait A2 { type F[X <: F, Y] } // error: cyclic reference involving type F
trait A3 { type F[X >: F, Y] } // error: cyclic reference involving type F

0 comments on commit c9220c2

Please sign in to comment.