Skip to content

Fix #11078: avoid widening F-bounds in type avoidance #11192

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
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dotc
package core

import Contexts._, Types._, Symbols._, Names._, Flags._
import SymDenotations._
import Denotations._, SymDenotations._
import util.Spans._
import util.Stats
import NameKinds.DepParamName
Expand Down Expand Up @@ -438,6 +438,8 @@ object TypeOps:
tp.origin, fromBelow = variance > 0 || variance == 0 && tp.hasLowerBound)(using mapCtx)
val lo1 = apply(lo)
if (lo1 ne lo) lo1 else tp
case tp: LazyRef =>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be emptyRange instead of TypeBounds.empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the tip, @odersky. I tried emptyRange, the test tests/run/i2895a.scala still fails. The problem is that LazyRef may leak into non-bounds places after asSeenFrom. It seems we need to stop earlier in the handling of bounds.

TypeBounds.empty
case _ =>
mapOver(tp)
}
Expand Down
29 changes: 29 additions & 0 deletions tests/pos/i11078.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
trait Foo[A <: Foo[A]]
trait FooCreator[A <: Foo[A]] {
def createFoo(): A
}

trait FooWrapper {
type A <: Foo[A]
def foo: A
}
object FooWrapper {
def apply[A0 <: Foo[A0]](toWrap: A0): FooWrapper { type A = A0 } = new FooWrapper {
type A = A0
def foo: A0 = toWrap
}
}

trait FooCreatorWrapper {
type A <: Foo[A]
def fooCreator: FooCreator[A]
}

sealed trait Bar
object Bar {
case class Baz(wrapper: FooCreatorWrapper) extends Bar
}

def process(bar: Bar): FooWrapper = bar match {
case Bar.Baz(wrapper) => FooWrapper(wrapper.fooCreator.createFoo())
}
11 changes: 11 additions & 0 deletions tests/pos/i11078b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Test {
trait Foo[A <: Foo[A]]

trait FooWrapper with self =>
type A <: Foo[A]
def doThing(foo: FooWrapper): FooWrapper { type A = self.A } = ???
end FooWrapper

val foos: scala.Seq[FooWrapper] = ???
val newFoo = foos.foldLeft(??? : FooWrapper)((topFoo, foo) => topFoo.doThing(foo))
}