diff options
-rw-r--r-- | src/reflect/scala/reflect/internal/Types.scala | 18 | ||||
-rw-r--r-- | test/files/pos/t5330.scala | 22 | ||||
-rw-r--r-- | test/files/pos/t5330b.scala | 6 | ||||
-rw-r--r-- | test/files/pos/t5330c.scala | 5 | ||||
-rw-r--r-- | test/files/pos/t6014.scala | 13 |
5 files changed, 61 insertions, 3 deletions
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index de6c6285ca..6df6ed4417 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -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 @@ -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) })}) { @@ -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)) })) { @@ -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) })}) { diff --git a/test/files/pos/t5330.scala b/test/files/pos/t5330.scala new file mode 100644 index 0000000000..813acd4b83 --- /dev/null +++ b/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)) +} diff --git a/test/files/pos/t5330b.scala b/test/files/pos/t5330b.scala new file mode 100644 index 0000000000..dbeb165cd8 --- /dev/null +++ b/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("!!!") +} diff --git a/test/files/pos/t5330c.scala b/test/files/pos/t5330c.scala new file mode 100644 index 0000000000..af31f3dfd1 --- /dev/null +++ b/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 )) +} diff --git a/test/files/pos/t6014.scala b/test/files/pos/t6014.scala new file mode 100644 index 0000000000..46e03bb552 --- /dev/null +++ b/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 +}
\ No newline at end of file |