Skip to content

Fixes for comparing and avoiding singletons #1458

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 3 commits into from
Aug 21, 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
12 changes: 4 additions & 8 deletions src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,10 @@ 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 match {
case tp2i: TermRef =>
isSubType(tp1, tp2i)
case ExprType(tp2i: TermRef) if (ctx.phase.id > ctx.gettersPhase.id) =>
// After getters, val x: T becomes def x: T
isSubType(tp1, tp2i)
case _ =>
false
tp2.info.widenExpr match {
case tp2i: SingletonType =>
isSubType(tp1, tp2i) // see z1720.scala for a case where this can arise even in typer.
case _ => false
}
case _ =>
false
Expand Down
5 changes: 4 additions & 1 deletion src/dotty/tools/dotc/typer/TypeAssigner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ trait TypeAssigner {
case _ => false
}
def apply(tp: Type): Type = tp match {
case tp: TermRef if toAvoid(tp) && variance > 0 =>
case tp: TermRef
if toAvoid(tp) && (variance > 0 || tp.info.widenExpr <:< tp) =>
// Can happen if `x: y.type`, then `x.type =:= y.type`, hence we can widen `x.type`
// to y.type in all contexts, not just covariant ones.
apply(tp.info.widenExpr)
case tp: TypeRef if toAvoid(tp) =>
tp.info match {
Expand Down
7 changes: 7 additions & 0 deletions test/dotc/tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ class tests extends CompilerTest {

@Test def pos_859 = compileFile(posSpecialDir, "i859", scala2mode)(allowDeepSubtypes)

@Test def pos_t5545 = {
// compile by hand in two batches, since junit lacks the infrastructure to
// compile files in multiple batches according to _1, _2, ... suffixes.
compileFile(posSpecialDir, "spec-t5545/S_1")
compileFile(posSpecialDir, "spec-t5545/S_2")
}

@Test def new_all = compileFiles(newDir, twice)
@Test def repl_all = replFiles(replDir)

Expand Down
File renamed without changes.