Skip to content

Fix #2064: Avoid illegal types in OrDominator #2068

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
Mar 9, 2017
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
10 changes: 4 additions & 6 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,10 @@ object Types {
* except for TypeRefs where the upper bound is returned, and HKApplys,
Copy link
Member

Choose a reason for hiding this comment

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

This comment is no longer accurate since this isn't limited to TypeRef anymore, right?

* where the upper bound of the constructor is re-applied to the arguments.
*/
def superType(implicit ctx: Context): Type = underlying
def superType(implicit ctx: Context): Type = underlying match {
case TypeBounds(_, hi) => hi
case st => st
}
}

// Every type has to inherit one of the following four abstract type classes.,
Expand Down Expand Up @@ -1762,11 +1765,6 @@ object Types {
type ThisType = TypeRef

override def underlying(implicit ctx: Context): Type = info

override def superType(implicit ctx: Context): Type = info match {
case TypeBounds(_, hi) => hi
case _ => info
}
}

final class TermRefWithSignature(prefix: Type, name: TermName, override val sig: Signature) extends TermRef(prefix, name) {
Expand Down
15 changes: 15 additions & 0 deletions tests/pos/i2064.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
object p {

class Foo[T] {
// Crashes:
def f(): Foo[T] = (if (true) this else this).bar

// Works:
// def f(): Foo[T] = new Bar(if (true) this else this).bar
}

implicit class Bar[A](val self: A) {
def bar(): A = self
}

}