From 130d4c35a425481839592496b523a8517bb03c71 Mon Sep 17 00:00:00 2001 From: odersky Date: Tue, 7 Jun 2022 12:09:05 +0200 Subject: [PATCH] Fix dependency status calculation for refined type aliases Fixes #15331 --- compiler/src/dotty/tools/dotc/core/Types.scala | 3 ++- .../dotty/tools/dotc/printing/PlainPrinter.scala | 2 +- tests/pos/i15331.scala | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i15331.scala diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 8b9f8690604e..6a5d48866158 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -3640,7 +3640,8 @@ object Types { (if status == TrueDeps then status else status | provisional).toByte def compute(status: DependencyStatus, tp: Type, theAcc: TypeAccumulator[DependencyStatus] | Null): DependencyStatus = def applyPrefix(tp: NamedType) = - if tp.currentSymbol.isStatic then status + if tp.isInstanceOf[SingletonType] && tp.currentSymbol.isStatic + then status // Note: a type ref with static symbol can still be dependent since the symbol might be refined in the enclosing type. See pos/15331.scala. else compute(status, tp.prefix, theAcc) if status == TrueDeps then status else tp match diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index 94c57e025067..d3545f09b0e7 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -325,7 +325,7 @@ class PlainPrinter(_ctx: Context) extends Printer { case tp @ ConstantType(value) => toText(value) case pref: TermParamRef => - nameString(pref.binder.paramNames(pref.paramNum)) + nameString(pref.binder.paramNames(pref.paramNum)) ~ lambdaHash(pref.binder) case tp: RecThis => val idx = openRecs.reverse.indexOf(tp.binder) if (idx >= 0) selfRecName(idx + 1) diff --git a/tests/pos/i15331.scala b/tests/pos/i15331.scala new file mode 100644 index 000000000000..faf9992cb4f2 --- /dev/null +++ b/tests/pos/i15331.scala @@ -0,0 +1,15 @@ +object Test: + trait Composable[A,B]: + def compose(a: A, b: B): Any + + trait Arrow {type Dom; type Codom} + + given composeArrows[A, Arr1 <: Arrow, Arr2 <: Arrow]: Composable[Arr1 {type Dom = A}, Arr2 {type Codom = A}] with + def compose(a: Arr1 {type Dom = A}, b: Arr2 {type Codom = A}): Arrow {type Dom = b.Dom; type Codom = a.Codom} = ??? + + object arr1 extends Arrow { type Dom = Int; type Codom = Int} + object arr2 extends Arrow {type Dom = Int; type Codom = Float} + + // removing "transparent" alleviates the situation + inline transparent def compose[A, B](a: A, b: B)(using c: Composable[A,B]) = c.compose(a,b) + val c = compose(arr2,arr1) \ No newline at end of file