Skip to content

Commit

Permalink
Merge pull request #15390 from dotty-staging/fix-15331
Browse files Browse the repository at this point in the history
Fix dependency status calculation for refined type aliases in method result types
  • Loading branch information
prolativ authored Jun 9, 2022
2 parents bfd9892 + 130d4c3 commit bbab0a9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions tests/pos/i15331.scala
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit bbab0a9

Please sign in to comment.