Skip to content
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

SI-7126 Account for the alias types that don't dealias. #2167

Merged
merged 2 commits into from Mar 2, 2013
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Expand Up @@ -222,8 +222,13 @@ trait Typers extends Modes with Adaptations with Tags {
new SubstWildcardMap(tparams).apply(tp)
case TypeRef(_, sym, _) if sym.isAliasType =>
val tp0 = tp.dealias
val tp1 = dropExistential(tp0)
if (tp1 eq tp0) tp else tp1
if (tp eq tp0) {
debugwarn(s"dropExistential did not progress dealiasing $tp, see SI-7126")
tp
} else {
val tp1 = dropExistential(tp0)
if (tp1 eq tp0) tp else tp1
}
case _ => tp
}

Expand Down
15 changes: 11 additions & 4 deletions src/reflect/scala/reflect/internal/Types.scala
Expand Up @@ -3183,12 +3183,19 @@ trait Types extends api.Types { self: SymbolTable =>
* ?TC[?T] <: Any
* }}}
*/
def unifySimple = (
(params.isEmpty || tp.typeSymbol == NothingClass || tp.typeSymbol == AnyClass) && {
def unifySimple = {
val sym = tp.typeSymbol
if (sym == NothingClass || sym == AnyClass) { // kind-polymorphic
// SI-7126 if we register some type alias `T=Any`, we can later end
// with malformed types like `T[T]` during type inference in
// `handlePolymorphicCall`. No such problem if we register `Any`.
addBound(sym.tpe)
true
} else if (params.isEmpty) {
addBound(tp)
true
}
)
} else false
}

/** Full case: involving a check of the form
* {{{
Expand Down
11 changes: 11 additions & 0 deletions test/files/pos/t7126.scala
@@ -0,0 +1,11 @@
import language._

object Test {
type T = Any
boom(???): Option[T] // SOE
def boom[CC[U]](t : CC[T]): Option[CC[T]] = None

// okay
foo(???): Option[Any]
def foo[CC[U]](t : CC[Any]): Option[CC[Any]] = None
}