From 11d71144d3059bcc0a07c04fcd2e880af8836ac8 Mon Sep 17 00:00:00 2001 From: odersky Date: Mon, 19 Sep 2022 12:06:01 +0200 Subject: [PATCH 1/2] Be even more careful when combining argument and info bounds in `computeAsSeenFrom` --- compiler/src/dotty/tools/dotc/core/Denotations.scala | 8 ++++++-- tests/pos/i16049.scala | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i16049.scala diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index a35f4d4c20c4..4366515b8ce3 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -1121,9 +1121,13 @@ object Denotations { else if symbol.isAllOf(ClassTypeParam) then val arg = symbol.typeRef.argForParam(pre, widenAbstract = true) if arg.exists then + // take the argument bounds, but intersect with the symbols bounds if + // this forces nothing and gives a non-empty type. val newBounds = - if symbol.isCompleted && !symbol.info.containsLazyRefs - then symbol.info.bounds & arg.bounds + if symbol.isCompleted && !symbol.info.containsLazyRefs then + val combined @ TypeBounds(lo, hi) = symbol.info.bounds & arg.bounds + if lo frozen_<:< hi then combined + else arg.bounds else arg.bounds derivedSingleDenotation(symbol, newBounds, pre) else derived(symbol.info) diff --git a/tests/pos/i16049.scala b/tests/pos/i16049.scala new file mode 100644 index 000000000000..8cb84eb7f217 --- /dev/null +++ b/tests/pos/i16049.scala @@ -0,0 +1,10 @@ +trait BatchDiffFunction[T] + +abstract class FirstOrderMinimizer[T, DF <: BatchDiffFunction[T]]: + type State = FirstOrderMinimizer.State[T] + +object FirstOrderMinimizer: + case class State[+T](x: T) + + class OptParams: + def iterations[T](init: T): Iterator[FirstOrderMinimizer[T, BatchDiffFunction[T]]#State] = ??? \ No newline at end of file From cf888c4dfd2feb29846a0564fd5f41a33d11b985 Mon Sep 17 00:00:00 2001 From: odersky Date: Tue, 20 Sep 2022 16:31:09 +0200 Subject: [PATCH 2/2] Regression test for #16076 --- tests/pos/i16076.scala | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/pos/i16076.scala diff --git a/tests/pos/i16076.scala b/tests/pos/i16076.scala new file mode 100644 index 000000000000..8347f0094a2c --- /dev/null +++ b/tests/pos/i16076.scala @@ -0,0 +1,9 @@ +trait Column[V] +trait ColumnPath + +trait ColumnFactory[V, C <: Column[V]]: + def apply(columnPath: ColumnPath): C + +object ColumnFactory: + private def apply[V, C <: Column[V]](f: String => C): ColumnFactory[V, C] = + columnPath => f(columnPath.toString())