summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2009-11-09 10:02:50 +0000
committerMartin Odersky <odersky@gmail.com>2009-11-09 10:02:50 +0000
commitc490722ae1b7a9147bcdc884e362409b4017d19f (patch)
treedff943acc82cfd98cd3247bf17f43cd91863cf94
parent6f4fba9c674d403372277b46c0455f38a1da1c4e (diff)
downloadscala-c490722ae1b7a9147bcdc884e362409b4017d19f.tar.gz
scala-c490722ae1b7a9147bcdc884e362409b4017d19f.tar.bz2
scala-c490722ae1b7a9147bcdc884e362409b4017d19f.zip
Fixed #2504
Fixed #2517
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Implicits.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala13
-rw-r--r--test/files/neg/t0851.check9
-rw-r--r--test/files/neg/t0851.scala25
-rwxr-xr-xtest/files/pos/t2082.scala39
-rwxr-xr-xtest/files/pos/t2504.scala5
-rwxr-xr-xtest/files/run/t2236.scala17
-rwxr-xr-xtest/files/run/t2503.scala19
8 files changed, 125 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
index 1e07442eee..75a6796be6 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
@@ -384,7 +384,7 @@ self: Analyzer =>
}
}
- if (traceImplicits) println("typed impl for "+wildPt+"? "+info.name+":"+depoly(info.tpe)+"/"+undetParams+"/"+isPlausiblyCompatible(info.tpe, wildPt)+"/"+matchesPt(depoly(info.tpe), wildPt, List()))
+ //if (traceImplicits) println("typed impl for "+wildPt+"? "+info.name+":"+depoly(info.tpe)+"/"+undetParams+"/"+isPlausiblyCompatible(info.tpe, wildPt)+"/"+matchesPt(depoly(info.tpe), wildPt, List()))
if (isPlausiblyCompatible(info.tpe, wildPt) &&
matchesPt(depoly(info.tpe), wildPt, List()) &&
isStable(info.pre)) {
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index c423258e00..3e83ecf272 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -841,6 +841,8 @@ trait Infer {
false
}
+ /** Todo: Try to make isApplicable always safe (i.e. not cause TypeErrors).
+ */
private[typechecker] def isApplicableSafe(undetparams: List[Symbol], ftpe: Type,
argtpes0: List[Type], pt: Type): Boolean = {
val reportAmbiguousErrors = context.reportAmbiguousErrors
@@ -849,7 +851,12 @@ trait Infer {
isApplicable(undetparams, ftpe, argtpes0, pt)
} catch {
case ex: TypeError =>
- false
+ try {
+ isApplicable(undetparams, ftpe, argtpes0, WildcardType)
+ } catch {
+ case ex: TypeError =>
+ false
+ }
} finally {
context.reportAmbiguousErrors = reportAmbiguousErrors
}
@@ -1379,7 +1386,7 @@ trait Infer {
check(pre, bound)
case TypeRef(pre, sym, args) =>
if (sym.isAbstractType)
- patternWarning(tp, "abstract type ")
+ if (!isLocalBinding(sym)) patternWarning(tp, "abstract type ")
else if (sym.isAliasType)
check(tp.normalize, bound)
else if (sym == NothingClass || sym == NullClass || sym == AnyValClass)
@@ -1624,7 +1631,7 @@ trait Infer {
log("infer method alt "+ tree.symbol +" with alternatives "+
(alts map pre.memberType) +", argtpes = "+ argtpes +", pt = "+ pt)
- val allApplicable = alts filter (alt =>
+ var allApplicable = alts filter (alt =>
isApplicable(undetparams, followApply(pre.memberType(alt)), argtpes, pt))
// if there are multiple, drop those that use a default
diff --git a/test/files/neg/t0851.check b/test/files/neg/t0851.check
new file mode 100644
index 0000000000..61d2a98632
--- /dev/null
+++ b/test/files/neg/t0851.check
@@ -0,0 +1,9 @@
+t0851.scala:14: error: not enough arguments for method apply: (v1: Int,v2: String)java.lang.String in trait Function2.
+Unspecified value parameter v2.
+ println(f(1))
+ ^
+t0851.scala:22: error: not enough arguments for method apply: (v1: Int,v2: String)java.lang.String in trait Function2.
+Unspecified value parameter v2.
+ println(fn(1))
+ ^
+two errors found
diff --git a/test/files/neg/t0851.scala b/test/files/neg/t0851.scala
new file mode 100644
index 0000000000..b28be2c697
--- /dev/null
+++ b/test/files/neg/t0851.scala
@@ -0,0 +1,25 @@
+package test
+
+// This gives now type errors about missing parameters, which seems OK to me.
+// The tests just make sure it does not crash
+
+object test1 {
+ case class Foo[T,T2](f : (T,T2) => String) extends (((T,T2)) => String){
+ def apply(t : T) = (s:T2) => f(t,s)
+ def apply(p : (T,T2)) = f(p._1,p._2)
+ }
+ implicit def g[T](f : (T,String) => String) = Foo(f)
+ def main(args : Array[String]) : Unit = {
+ val f = (x:Int,s:String) => s + x
+ println(f(1))
+ ()
+ }
+}
+object Main {
+ def main(args : Array[String]) {
+ val fn = (a : Int, str : String) => "a: " + a + ", str: " + str
+ implicit def fx[T](f : (T,String) => String) = (x:T) => f(x,null)
+ println(fn(1))
+ ()
+ }
+}
diff --git a/test/files/pos/t2082.scala b/test/files/pos/t2082.scala
new file mode 100755
index 0000000000..3a160612fe
--- /dev/null
+++ b/test/files/pos/t2082.scala
@@ -0,0 +1,39 @@
+
+trait Mapper[T <: Mapper[T]]
+
+trait KeyedMapper[KeyType, T <: KeyedMapper[KeyType, T]] extends Mapper[T]
+
+
+trait KeyedMetaMapper[KeyType, T <: KeyedMapper[KeyType, T]]
+
+trait MappedForeignKey[KeyType, Owner <: Mapper[Owner], Other <: KeyedMapper[KeyType, Other]]
+
+trait IdPK
+
+class TestSubject extends KeyedMapper[Long, TestSubject] with IdPK
+
+class TestRun extends KeyedMapper[Long, TestRun] with IdPK {
+ object testSubject extends MappedForeignKey[Long, TestRun, TestSubject]
+}
+
+object TestRun extends TestRun with KeyedMetaMapper[Long, TestRun]
+
+class MetaTestSubject extends TestSubject with KeyedMetaMapper[Long, TestSubject]
+object TestSubject extends MetaTestSubject
+
+object Main {
+
+ def oneToOneJoin[PType <: KeyedMapper[Long, PType] with IdPK,
+ CType <: KeyedMapper[Long, CType] with IdPK,
+ CMetaType <: CType with KeyedMetaMapper[Long, CType],
+ FKType <: MappedForeignKey[Long, PType, CType]]
+ (parents: List[PType], metaMapper: CMetaType, keyGetter: (PType) => FKType ):
+ Map[Long, CType] = Map.empty
+
+ def callIt {
+ oneToOneJoin[TestRun, TestSubject, MetaTestSubject,
+ MappedForeignKey[Long, TestRun, TestSubject]](
+ List(), TestSubject, (tr: TestRun) => tr.testSubject)
+ }
+
+}
diff --git a/test/files/pos/t2504.scala b/test/files/pos/t2504.scala
new file mode 100755
index 0000000000..67f8226852
--- /dev/null
+++ b/test/files/pos/t2504.scala
@@ -0,0 +1,5 @@
+object Test {
+ val ys: Iterable[_] = Array("abc")
+ val xs = Array("abc")
+ xs sameElements Array("abc")
+}
diff --git a/test/files/run/t2236.scala b/test/files/run/t2236.scala
new file mode 100755
index 0000000000..8e2b3900d4
--- /dev/null
+++ b/test/files/run/t2236.scala
@@ -0,0 +1,17 @@
+class T[A](implicit val m:Manifest[A])
+class Foo
+class Bar extends T[Foo]
+object Test extends Application {
+ new Bar
+}
+
+object EvidenceTest {
+ trait E[T]
+ trait A[T] { implicit val e: E[T] = null }
+ class B[T : E] extends A[T] { override val e = null }
+
+ def f[T] {
+ implicit val e: E[T] = null
+ new B[T]{}
+ }
+}
diff --git a/test/files/run/t2503.scala b/test/files/run/t2503.scala
new file mode 100755
index 0000000000..353a1dcac8
--- /dev/null
+++ b/test/files/run/t2503.scala
@@ -0,0 +1,19 @@
+import scala.collection.mutable._
+
+trait SB[A] extends Buffer[A] {
+
+ import collection.Traversable
+
+ abstract override def insertAll(n: Int, iter: Traversable[A]): Unit = synchronized {
+ super.insertAll(n, iter)
+ }
+
+ abstract override def update(n: Int, newelem: A): Unit = synchronized {
+ super.update(n, newelem)
+ }
+}
+
+object Test extends Application {
+ new ArrayBuffer[Int] with SB[Int]
+}
+