From 4e27694dd9090a3891bdf8531ddd4d3896af0956 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Wed, 18 Sep 2024 18:14:48 +0200 Subject: [PATCH 1/2] Revert "Reduce projections of type aliases with class type prefixes" --- .../src/dotty/tools/dotc/core/Types.scala | 16 +++--------- tests/pos/i19892.scala | 26 ------------------- 2 files changed, 4 insertions(+), 38 deletions(-) delete mode 100644 tests/pos/i19892.scala diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 4b426bb8c741..2d3027504936 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -2598,22 +2598,14 @@ object Types extends TypeUtils { case _ => true } - /** Reduce a type ref P # X, where X is a type alias and P is a refined type or - * a class type. If P is a refined type `T { X = U; ... }`, reduce P to U, - * provided U does not refer with a RecThis to the same refined type. If P is a - * class type, reduce it to the dealiasd version of P # X. This means that at typer - * we create projections only for inner classes with class prefixes, since projections - * of P # X where X is an abstract type are handled by skolemization. At later phases - * these projections might arise, though. + /** Reduce a type-ref `T { X = U; ... } # X` to `U` + * provided `U` does not refer with a RecThis to the + * refinement type `T { X = U; ... }` */ def reduceProjection(using Context): Type = if (isType) { val reduced = prefix.lookupRefined(name) - if reduced.exists then reduced - else prefix.stripTypeVar match - case pre: (AppliedType | TypeRef) - if prefix.dealias.typeSymbol.isClass && this.symbol.isAliasType => dealias - case _ => this + if reduced.exists then reduced else this } else this diff --git a/tests/pos/i19892.scala b/tests/pos/i19892.scala deleted file mode 100644 index 6f3e0bd6d06c..000000000000 --- a/tests/pos/i19892.scala +++ /dev/null @@ -1,26 +0,0 @@ -abstract class ZPartialServerEndpoint[R, A, B, I, E, O, -C] - extends EndpointOps[A, I, E, O, C]{ - override type ThisType[-_R] = ZPartialServerEndpoint[R, A, B, I, E, O, _R] - override type EndpointType[_A, _I, _E, _O, -_R] =ZPartialServerEndpoint[R, _A, B, _I, _E, _O, _R] -} - -trait EndpointOps[A, I, E, O, -R] { - type EndpointType[_A, _I, _E, _O, -_R] - type ThisType[-_R] - def out[T]: EndpointType[A, I, E, T, R] - def description(d: String): ThisType[R] -} - -object Test { - def basicEndpoint[R](): ZPartialServerEndpoint[R, Any, Any, Unit, Any, Unit, Any] = ??? - - // commonts next to `.out[Any]` contain information about compilation time when chaining up to N `out` functions - val case1 = - basicEndpoint() // 1.5s - .out[Any] // 1.6s - .out[Any] // 1.7s - .out[Any] // 2s - .out[Any] // 4s - .out[Any] // 33s - .out[Any] // aborted after 5 min -} \ No newline at end of file From 1b9d12cbf198b63c02687eda62354169399c7848 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Wed, 18 Sep 2024 18:15:07 +0200 Subject: [PATCH 2/2] Add regresion test for #21576 --- tests/run/i21576.check | 3 +++ tests/run/i21576.scala | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/run/i21576.check create mode 100644 tests/run/i21576.scala diff --git a/tests/run/i21576.check b/tests/run/i21576.check new file mode 100644 index 000000000000..1bbe534c2782 --- /dev/null +++ b/tests/run/i21576.check @@ -0,0 +1,3 @@ +public SubFlow(SubFlowDef>,SubFlowDef>) +public SubFlowDef> SubFlow.delegate1() +public SubFlowDef> SubFlow.delegate2() diff --git a/tests/run/i21576.scala b/tests/run/i21576.scala new file mode 100644 index 000000000000..6b5515ac7719 --- /dev/null +++ b/tests/run/i21576.scala @@ -0,0 +1,31 @@ +// scalajs: --skip +import scala.annotation.unchecked.uncheckedVariance + +trait SubFlowDef[+F[+_]] +final class Flow1[-In]{ + type Repr[+O] = Flow1[In @uncheckedVariance] +} +final class Flow2[+Out]{ + type Repr[+O] = Flow2[O] +} +class SubFlow[In, Out]( + val delegate1: SubFlowDef[Flow1[In]#Repr], + val delegate2: SubFlowDef[Flow2[Out]#Repr] +) + +object Test { + def main(args: Array[String]): Unit = { + classOf[SubFlow[?, ?]] + .getConstructors() + .map(_.toGenericString()) + .sorted + .foreach(println) + + classOf[SubFlow[?, ?]] + .getMethods() + .filter(_.getName().startsWith("delegate")) + .map(_.toGenericString()) + .sorted + .foreach(println) + } +}