Skip to content

Fix bounds propagation #232

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

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 3 additions & 1 deletion src/dotty/tools/dotc/core/TypeApplications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,10 @@ class TypeApplications(val self: Type) extends AnyVal {
*/
final def toBounds(tparam: Symbol)(implicit ctx: Context): TypeBounds = self match {
case self: TypeBounds => // this can happen for wildcard args
self
self & tparam.info.bounds
case _ =>
// no within-bounds check done here because of risk of cycles. Thsi is done later
// for source generated types using checkBounds.
val v = tparam.variance
if (v > 0 && !(tparam is Local) && !(tparam is ExpandedTypeParam)) TypeBounds.upper(self)
else if (v < 0 && !(tparam is Local) && !(tparam is ExpandedTypeParam)) TypeBounds.lower(self)
Expand Down
1 change: 1 addition & 0 deletions test/dotc/tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class tests extends CompilerTest {
@Test def neg_typetest = compileFile(negDir, "typetest", xerrors = 1)
@Test def neg_t1569_failedAvoid = compileFile(negDir, "t1569-failedAvoid", xerrors = 1)
@Test def neg_cycles = compileFile(negDir, "cycles", xerrors = 6)
@Test def neg_boundspropagation = compileFile(negDir, "boundspropagation", xerrors = 2)

@Test def dotc = compileDir(dotcDir + "tools/dotc", twice)(allowDeepSubtypes)
@Test def dotc_ast = compileDir(dotcDir + "tools/dotc/ast", twice)
Expand Down
26 changes: 26 additions & 0 deletions tests/neg/boundspropagation.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// scalac fails for test2/3
// dotc fails for all three
object test1 {
class Tree[-T >: Null]


def f(x: Any): Tree[Null] = x match {
case y: Tree[_] => y
}
}
object test2 {
class Tree[T >: Null]


def f(x: Any): Tree[Null] = x match {
case y: Tree[_] => y
}
}
object test3 {
class Tree[+T >: Null]


def f(x: Any): Tree[Null] = x match {
case y: Tree[_] => y
}
}
7 changes: 4 additions & 3 deletions tests/pending/pos/boundspropagation.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// scalac fails for test2/3
// dotc fails for all three
// dotc used to fail for all three
object test1 {
class Tree[-T >: Null]

Expand All @@ -8,7 +8,7 @@ object test1 {
case y: Tree[_] => y
}
}
object test2 {
/*object test2 {
class Tree[T >: Null]


Expand All @@ -22,5 +22,6 @@ object test3 {

def f(x: Any): Tree[Null] = x match {
case y: Tree[_] => y
}
}
}
*/