Skip to content

Commit

Permalink
Merge pull request #1624 from adriaanm/paulp-issue/5330-2.10.x
Browse files Browse the repository at this point in the history
SI-5330, SI-6014 deal with existential self-type
  • Loading branch information
adriaanm committed Nov 16, 2012
2 parents 73d9ae5 + 65778d7 commit 2d62ab2
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/reflect/scala/reflect/internal/Types.scala
Expand Up @@ -325,6 +325,18 @@ trait Types extends api.Types { self: SymbolTable =>
}
}

/** Same as a call to narrow unless existentials are visible
* after widening the type. In that case, narrow from the widened
* type instead of the proxy. This gives buried existentials a
* chance to make peace with the other types. See SI-5330.
*/
private def narrowForFindMember(tp: Type): Type = {
val w = tp.widen
// Only narrow on widened type when we have to -- narrow is expensive unless the target is a singleton type.
if ((tp ne w) && containsExistential(w)) w.narrow
else tp.narrow
}

/** The base class for all types */
abstract class Type extends TypeApiImpl with Annotatable[Type] {
/** Types for which asSeenFrom always is the identity, no matter what
Expand Down Expand Up @@ -1079,7 +1091,7 @@ trait Types extends api.Types { self: SymbolTable =>
(other ne sym) &&
((other.owner eq sym.owner) ||
(flags & PRIVATE) != 0 || {
if (self eq null) self = this.narrow
if (self eq null) self = narrowForFindMember(this)
if (symtpe eq null) symtpe = self.memberType(sym)
!(self.memberType(other) matches symtpe)
})}) {
Expand Down Expand Up @@ -1161,7 +1173,7 @@ trait Types extends api.Types { self: SymbolTable =>
if ((member ne sym) &&
((member.owner eq sym.owner) ||
(flags & PRIVATE) != 0 || {
if (self eq null) self = this.narrow
if (self eq null) self = narrowForFindMember(this)
if (membertpe eq null) membertpe = self.memberType(member)
!(membertpe matches self.memberType(sym))
})) {
Expand All @@ -1176,7 +1188,7 @@ trait Types extends api.Types { self: SymbolTable =>
(other ne sym) &&
((other.owner eq sym.owner) ||
(flags & PRIVATE) != 0 || {
if (self eq null) self = this.narrow
if (self eq null) self = narrowForFindMember(this)
if (symtpe eq null) symtpe = self.memberType(sym)
!(self.memberType(other) matches symtpe)
})}) {
Expand Down
22 changes: 22 additions & 0 deletions test/files/pos/t5330.scala
@@ -0,0 +1,22 @@
trait FM[A] {
def map(f: A => Any)
}

trait M[A] extends FM[A] {
def map(f: A => Any)
}

trait N[A] extends FM[A]

object test {
def kaboom(xs: M[_]) = xs map (x => ()) // missing parameter type.

def okay1[A](xs: M[A]) = xs map (x => ())
def okay2(xs: FM[_]) = xs map (x => ())
def okay3(xs: N[_]) = xs map (x => ())
}

class CC2(xs: List[_]) {
def f(x1: Any, x2: Any) = null
def g = xs map (x => f(x, x))
}
6 changes: 6 additions & 0 deletions test/files/pos/t5330b.scala
@@ -0,0 +1,6 @@
abstract trait Base {
def foo: this.type
};
class Derived[T] extends Base {
def foo: Nothing = sys.error("!!!")
}
5 changes: 5 additions & 0 deletions test/files/pos/t5330c.scala
@@ -0,0 +1,5 @@
object t5330c {
val s: Set[_ >: Char] = Set('A')
s forall ("ABC" contains _)
s.forall( c => "ABC".toSeq.contains( c ))
}
13 changes: 13 additions & 0 deletions test/files/pos/t6014.scala
@@ -0,0 +1,13 @@
object Test {
case class CC[T](key: T)
type Alias[T] = Seq[CC[T]]

def f(xs: Seq[CC[_]]) = xs map { case CC(x) => CC(x) } // ok
def g(xs: Alias[_]) = xs map { case CC(x) => CC(x) } // fails
// ./a.scala:11: error: missing parameter type for expanded function
// The argument types of an anonymous function must be fully known. (SLS 8.5)
// Expected type was: ?
// def g(xs: Alias[_]) = xs map { case CC(x) => CC(x) } // fails
// ^
// one error found
}

0 comments on commit 2d62ab2

Please sign in to comment.