Skip to content

Fix dependency status calculation for refined type aliases in method result types #15390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)