File tree 3 files changed +34
-5
lines changed
compiler/src/dotty/tools/dotc/core
3 files changed +34
-5
lines changed Original file line number Diff line number Diff line change @@ -970,12 +970,15 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
970
970
compareAppliedType1(tp1, tycon1, args1)
971
971
case tp1 : SingletonType =>
972
972
def comparePaths = tp2 match
973
- case tp2 : TermRef =>
973
+ case tp2 : ( TermRef | ThisType ) =>
974
974
compareAtoms(tp1, tp2, knownSingletons = true ).getOrElse(false )
975
- || { // needed to make from-tasty work. test cases: pos/i1753.scala, pos/t839.scala
976
- tp2.info.widenExpr.dealias match
977
- case tp2i : SingletonType => recur(tp1, tp2i)
978
- case _ => false
975
+ || {
976
+ // If tp2's underlying type tp2super is also effectively a singleton, compare
977
+ // against that. The idea is that if tp1 <: tp2super and tp2 <: tp2super and
978
+ // tp2super is also singleton, then tp1 and tp2 must be the same singleton.
979
+ // Needed to make from-tasty work. test cases: pos/i1753.scala, pos/t839.scala
980
+ val tp2super = tp2.superType.widenExpr
981
+ tp2super.isEffectivelySingleton && recur(tp1, tp2super)
979
982
}
980
983
case _ => false
981
984
Original file line number Diff line number Diff line change @@ -328,6 +328,16 @@ object Types extends TypeUtils {
328
328
/** Is this type a (possibly aliased) singleton type? */
329
329
def isSingleton (using Context ): Boolean = dealias.isInstanceOf [SingletonType ]
330
330
331
+ /** Is this type a (possibly aliased) singleton type or a type proxy
332
+ * or Or/And type known to be a singleton type?
333
+ */
334
+ def isEffectivelySingleton (using Context ): Boolean = dealias match
335
+ case tp : SingletonType => true
336
+ case tp : TypeProxy => tp.superType.isEffectivelySingleton
337
+ case AndType (tpL, tpR) => tpL.isEffectivelySingleton || tpR.isEffectivelySingleton
338
+ case OrType (tpL, tpR) => tpL.isEffectivelySingleton && tpR.isEffectivelySingleton
339
+ case _ => false
340
+
331
341
/** Is this upper-bounded by a (possibly aliased) singleton type?
332
342
* Overridden in TypeVar
333
343
*/
Original file line number Diff line number Diff line change
1
+ sealed trait Schema [A ]
2
+
3
+ object Schema extends RecordInstances :
4
+ case class Field [A ]()
5
+
6
+ sealed trait RecordInstances :
7
+ self : Schema .type =>
8
+
9
+ case class Record [A ](field : Field [A ]) extends Schema [A ]
10
+
11
+ import Schema ._
12
+
13
+ val field : Field [Int ] = Field ()
14
+
15
+ // Uh oh Found Playground.Schema.Field[Int] but Requried RecordInstances.this.Field[Int]
16
+ val record = Record [Int ](field)
You can’t perform that action at this time.
0 commit comments