From eab74a33579636f385d4687e30e811f262d13a0e Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 30 Nov 2016 15:48:21 +0100 Subject: [PATCH] Fix $1753 Better comparison of path types In this case, a path went through a type parameter which was aliased to a singleton type. Need to dealias to get to the special case handling two paths. --- .../dotty/tools/dotc/core/TypeComparer.scala | 6 +++-- tests/pos/i1753.scala | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i1753.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index f78820fff32c..fd954c688dbd 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -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. case _ => false } case _ => diff --git a/tests/pos/i1753.scala b/tests/pos/i1753.scala new file mode 100644 index 000000000000..e5ad743aaac8 --- /dev/null +++ b/tests/pos/i1753.scala @@ -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 + def getPlainClass(cd: ClassDef) = bTypes.isRemote(null: Symbol) +}