Skip to content

Commit 94d80f1

Browse files
committed
Removes buggy implicit logs
Fixes scala#6315 (comment)
1 parent cee723e commit 94d80f1

File tree

3 files changed

+121
-5
lines changed

3 files changed

+121
-5
lines changed

src/compiler/scala/tools/nsc/typechecker/Contexts.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -842,13 +842,11 @@ trait Contexts { self: Analyzer =>
842842
private def isQualifyingImplicit(name: Name, sym: Symbol, pre: Type, imported: Boolean) =
843843
sym.isImplicit &&
844844
isAccessible(sym, pre) &&
845-
!({
845+
!(
846846
// [eed3si9n] ideally I'd like to do this: val fd = settings.isScala214 && sym.isDeprecated
847847
// but implicit caching currently does not report sym.isDeprecated correctly.
848-
val fd = settings.isScala214 && (sym == currentRun.runDefinitions.Predef_any2stringaddMethod)
849-
if (settings.XlogImplicits && fd) echo(sym.pos, sym + " is not a valid implicit value because:\n" + "-Xsource:2.14 removes scala.Predef.any2stringadd")
850-
fd
851-
}) &&
848+
settings.isScala214 && (sym == currentRun.runDefinitions.Predef_any2stringaddMethod)
849+
) &&
852850
!(imported && {
853851
val e = scope.lookupEntry(name)
854852
(e ne null) && (e.owner == scope) && (!settings.isScala212 || e.sym.exists)

test/files/neg/implicit-log.check

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
implicit-log.scala:61: byVal is not a valid implicit value for Int(7) => ?{def unwrap: ?} because:
2+
incompatible: (x: 7)7 does not match expected type Int(7) => ?{def unwrap: ?}
3+
val res = 7.unwrap() // doesn't work
4+
^
5+
implicit-log.scala:70: materializing requested scala.reflect.type.ClassTag[String] using scala.reflect.`package`.materializeClassTag[String]()
6+
val x: java.util.List[String] = List("foo")
7+
^
8+
implicit-log.scala:70: materializing requested scala.reflect.type.ClassTag[String] using scala.reflect.`package`.materializeClassTag[String]()
9+
val x: java.util.List[String] = List("foo")
10+
^
11+
implicit-log.scala:96: materializing requested reflect.runtime.universe.type.TypeTag[Class[_]] using scala.reflect.api.`package`.materializeTypeTag[Class[_]](scala.reflect.runtime.`package`.universe)
12+
println(implicitly[TypeTag[Class[_]]])
13+
^
14+
implicit-log.scala:100: error: value baa is not a member of Int
15+
1.baa
16+
^
17+
one error found

test/files/neg/implicit-log.scala

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/* scalac: -Xlog-implicits -Xsource:2.14 -Xfatal-warnings */
2+
3+
package foo
4+
5+
import scala.language.implicitConversions
6+
import scala.reflect.runtime.universe._
7+
import scala.reflect.{ClassTag, classTag}
8+
9+
// #1435
10+
object t1435 {
11+
implicit def a(s:String):String = sys.error("")
12+
implicit def a(i:Int):String = sys.error("")
13+
implicit def b(i:Int):String = sys.error("")
14+
}
15+
16+
class C1435 {
17+
val v:String = {
18+
import t1435.a
19+
2
20+
}
21+
}
22+
23+
// #1492
24+
class C1492 {
25+
26+
class X
27+
28+
def foo(x: X => X): Unit = {}
29+
30+
foo ( implicit x => implicitly[X] )
31+
foo { implicit x => implicitly[X] }
32+
}
33+
34+
// #1579
35+
object Test1579 {
36+
class Column
37+
class Query[E](val value: E)
38+
class Invoker(q: Any) { val foo = null }
39+
40+
implicit def unwrap[C](q: Query[C]) = q.value
41+
implicit def invoker(q: Query[Column]) = new Invoker(q)
42+
43+
val q = new Query(new Column)
44+
q.foo
45+
}
46+
// #1625
47+
object Test1625 {
48+
49+
class Wrapped(x:Any) {
50+
def unwrap() = x
51+
}
52+
53+
implicit def byName[A](x: =>A) = new Wrapped(x)
54+
55+
implicit def byVal[A](x: A) = x
56+
57+
def main(args: Array[String]) = {
58+
59+
// val res:Wrapped = 7 // works
60+
61+
val res = 7.unwrap() // doesn't work
62+
63+
println("=> result: " + res)
64+
}
65+
}
66+
67+
object Test2188 {
68+
implicit def toJavaList[A: ClassTag](t:collection.Seq[A]):java.util.List[A] = java.util.Arrays.asList(t.toArray:_*)
69+
70+
val x: java.util.List[String] = List("foo")
71+
}
72+
73+
object TestNumericWidening {
74+
val y = 1
75+
val x: java.lang.Long = y
76+
}
77+
78+
// #2709
79+
package foo2709 {
80+
class A
81+
class B
82+
83+
package object bar {
84+
implicit def a2b(a: A): B = new B
85+
}
86+
87+
package bar {
88+
object test {
89+
new A: B
90+
}
91+
}
92+
}
93+
94+
// Problem with specs
95+
object specsProblem {
96+
println(implicitly[TypeTag[Class[_]]])
97+
}
98+
99+
object Foo {
100+
1.baa
101+
}

0 commit comments

Comments
 (0)