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 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
15 changes: 7 additions & 8 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1273,10 +1273,14 @@ object Types {
def underlying(implicit ctx: Context): Type

/** The closest supertype of this type. This is the same as `underlying`,
* except for TypeRefs where the upper bound is returned, and HKApplys,
* where the upper bound of the constructor is re-applied to the arguments.
* except that
* - instead of a TyperBounds type it returns its upper bound, and
* - for HKApplys it returns the upper bound of the constructor 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 +1766,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
}

}