Skip to content

Commit bbab0a9

Browse files
authored
Merge pull request #15390 from dotty-staging/fix-15331
Fix dependency status calculation for refined type aliases in method result types
2 parents bfd9892 + 130d4c3 commit bbab0a9

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3640,7 +3640,8 @@ object Types {
36403640
(if status == TrueDeps then status else status | provisional).toByte
36413641
def compute(status: DependencyStatus, tp: Type, theAcc: TypeAccumulator[DependencyStatus] | Null): DependencyStatus =
36423642
def applyPrefix(tp: NamedType) =
3643-
if tp.currentSymbol.isStatic then status
3643+
if tp.isInstanceOf[SingletonType] && tp.currentSymbol.isStatic
3644+
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.
36443645
else compute(status, tp.prefix, theAcc)
36453646
if status == TrueDeps then status
36463647
else tp match

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
325325
case tp @ ConstantType(value) =>
326326
toText(value)
327327
case pref: TermParamRef =>
328-
nameString(pref.binder.paramNames(pref.paramNum))
328+
nameString(pref.binder.paramNames(pref.paramNum)) ~ lambdaHash(pref.binder)
329329
case tp: RecThis =>
330330
val idx = openRecs.reverse.indexOf(tp.binder)
331331
if (idx >= 0) selfRecName(idx + 1)

tests/pos/i15331.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
object Test:
2+
trait Composable[A,B]:
3+
def compose(a: A, b: B): Any
4+
5+
trait Arrow {type Dom; type Codom}
6+
7+
given composeArrows[A, Arr1 <: Arrow, Arr2 <: Arrow]: Composable[Arr1 {type Dom = A}, Arr2 {type Codom = A}] with
8+
def compose(a: Arr1 {type Dom = A}, b: Arr2 {type Codom = A}): Arrow {type Dom = b.Dom; type Codom = a.Codom} = ???
9+
10+
object arr1 extends Arrow { type Dom = Int; type Codom = Int}
11+
object arr2 extends Arrow {type Dom = Int; type Codom = Float}
12+
13+
// removing "transparent" alleviates the situation
14+
inline transparent def compose[A, B](a: A, b: B)(using c: Composable[A,B]) = c.compose(a,b)
15+
val c = compose(arr2,arr1)

0 commit comments

Comments
 (0)