From bc621bad33cc897f43f2b30d1c8afe1912919cfe Mon Sep 17 00:00:00 2001
From: Paolo Giarrusso
Date: Wed, 22 Aug 2012 20:22:54 +0200
Subject: Ensure implicit conversions to concurrent map are unambiguous
Even after the parent change, implicit conversions should still convert
ConcurrentHashMap to concurrent.Map and not to mutable.ConcurrentMap.
I'll include the comment by axel22 which prompting this change (taken
from https://github.com/scala/scala/pull/1172#issuecomment-7928285)
since it is highly informative and links to pull request comments might
not be very stable:
<<
Instead of just testing an implicit conversion to ConcurrentMap, the
test should call ConcurrentMap methods such as putIfAbsent (which
returns an Option[T]) and replace, to see if the correct Scala
concurrent map trait is being resolved.
The problem is that putIfAbsent already exists on juc.ConcurrentMap so
instead of triggering an implicit conversion, a type mismatch error is
output anyway.
And we cannot test that the correct concurrent map trait is returned
using methods like map, flatMap and friends, because concurrent map
traits extends mutable.Map anyway.
For this reason, I recommend to add this to the test:
scala> val a = new java.util.concurrent.ConcurrentHashMap[String,
String]() += (("", ""))
a: scala.collection.concurrent.Map[String,String] = Map("" -> "")
and make sure that the returned map is concurrent.Map, not
mutable.ConcurrentMap (the above += is one of the few methods in
collection that has the return type this.type).
>>
---
test/files/neg/javaConversions-2.10-ambiguity.scala | 10 ++++++++++
1 file changed, 10 insertions(+)
create mode 100644 test/files/neg/javaConversions-2.10-ambiguity.scala
(limited to 'test/files/neg/javaConversions-2.10-ambiguity.scala')
diff --git a/test/files/neg/javaConversions-2.10-ambiguity.scala b/test/files/neg/javaConversions-2.10-ambiguity.scala
new file mode 100644
index 0000000000..e856846a29
--- /dev/null
+++ b/test/files/neg/javaConversions-2.10-ambiguity.scala
@@ -0,0 +1,10 @@
+import collection.{JavaConversions, mutable, concurrent}
+import JavaConversions._
+import java.util.concurrent.{ConcurrentHashMap => CHM}
+
+object Bar {
+ def assertType[T](t: T) = t
+ val a = new CHM[String, String]() += (("", ""))
+ assertType[mutable.ConcurrentMap[String, String]](a)
+}
+// vim: set et:
--
cgit v1.2.3