Skip to content

Fix #1753: Better comparison of path types #1760

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
Nov 30, 2016
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
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,11 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
/** if `tp2 == p.type` and `p: q.type` then try `tp1 <:< q.type` as a last effort.*/
def comparePaths = tp2 match {
case tp2: TermRef =>
tp2.info.widenExpr match {
tp2.info.widenExpr.dealias match {
case tp2i: SingletonType =>
isSubType(tp1, tp2i) // see z1720.scala for a case where this can arise even in typer.
isSubType(tp1, tp2i)
// see z1720.scala for a case where this can arise even in typer.
// Also, i1753.scala, to show why the dealias above is necessary.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strange indentation here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use this style on occasion. Basically, if an end of line comment is too long I put several
indented lines after the commented statement. I find it sometimes clearer than having the comments before (depends on the wording of the comment).

case _ => false
}
case _ =>
Expand Down
22 changes: 22 additions & 0 deletions tests/pos/i1753.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
abstract class BackendInterface {
type Symbol >: Null
type ClassDef >: Null
}

class BTypesFromSymbols[I <: BackendInterface](val int: I) {
def isRemote(s: int.Symbol) = println("might've been remote")
}

trait BCodeIdiomatic {
val int: BackendInterface
final lazy val bTypes = new BTypesFromSymbols[int.type](int)
}

trait BCodeSkelBuilder extends BCodeIdiomatic {
import int._
import bTypes._
val b: BTypesFromSymbols[int.type] = bTypes
val x: int.type = bTypes.int
val y: bTypes.int.type = int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these two lines with x and y?

Used it for debugging?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break the problem apart into two subtype tests. I thought it was good to add this.

def getPlainClass(cd: ClassDef) = bTypes.isRemote(null: Symbol)
}