Skip to content

Commit

Permalink
Removes buggy implicit logs
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed Jun 12, 2018
1 parent cee723e commit 94d80f1
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/compiler/scala/tools/nsc/typechecker/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -842,13 +842,11 @@ trait Contexts { self: Analyzer =>
private def isQualifyingImplicit(name: Name, sym: Symbol, pre: Type, imported: Boolean) =
sym.isImplicit &&
isAccessible(sym, pre) &&
!({
!(
// [eed3si9n] ideally I'd like to do this: val fd = settings.isScala214 && sym.isDeprecated
// but implicit caching currently does not report sym.isDeprecated correctly.
val fd = settings.isScala214 && (sym == currentRun.runDefinitions.Predef_any2stringaddMethod)
if (settings.XlogImplicits && fd) echo(sym.pos, sym + " is not a valid implicit value because:\n" + "-Xsource:2.14 removes scala.Predef.any2stringadd")
fd
}) &&
settings.isScala214 && (sym == currentRun.runDefinitions.Predef_any2stringaddMethod)
) &&
!(imported && {
val e = scope.lookupEntry(name)
(e ne null) && (e.owner == scope) && (!settings.isScala212 || e.sym.exists)
Expand Down
17 changes: 17 additions & 0 deletions test/files/neg/implicit-log.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
implicit-log.scala:61: byVal is not a valid implicit value for Int(7) => ?{def unwrap: ?} because:
incompatible: (x: 7)7 does not match expected type Int(7) => ?{def unwrap: ?}
val res = 7.unwrap() // doesn't work
^
implicit-log.scala:70: materializing requested scala.reflect.type.ClassTag[String] using scala.reflect.`package`.materializeClassTag[String]()
val x: java.util.List[String] = List("foo")
^
implicit-log.scala:70: materializing requested scala.reflect.type.ClassTag[String] using scala.reflect.`package`.materializeClassTag[String]()
val x: java.util.List[String] = List("foo")
^
implicit-log.scala:96: materializing requested reflect.runtime.universe.type.TypeTag[Class[_]] using scala.reflect.api.`package`.materializeTypeTag[Class[_]](scala.reflect.runtime.`package`.universe)
println(implicitly[TypeTag[Class[_]]])
^
implicit-log.scala:100: error: value baa is not a member of Int
1.baa
^
one error found
101 changes: 101 additions & 0 deletions test/files/neg/implicit-log.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/* scalac: -Xlog-implicits -Xsource:2.14 -Xfatal-warnings */

package foo

import scala.language.implicitConversions
import scala.reflect.runtime.universe._
import scala.reflect.{ClassTag, classTag}

// #1435
object t1435 {
implicit def a(s:String):String = sys.error("")
implicit def a(i:Int):String = sys.error("")
implicit def b(i:Int):String = sys.error("")
}

class C1435 {
val v:String = {
import t1435.a
2
}
}

// #1492
class C1492 {

class X

def foo(x: X => X): Unit = {}

foo ( implicit x => implicitly[X] )
foo { implicit x => implicitly[X] }
}

// #1579
object Test1579 {
class Column
class Query[E](val value: E)
class Invoker(q: Any) { val foo = null }

implicit def unwrap[C](q: Query[C]) = q.value
implicit def invoker(q: Query[Column]) = new Invoker(q)

val q = new Query(new Column)
q.foo
}
// #1625
object Test1625 {

class Wrapped(x:Any) {
def unwrap() = x
}

implicit def byName[A](x: =>A) = new Wrapped(x)

implicit def byVal[A](x: A) = x

def main(args: Array[String]) = {

// val res:Wrapped = 7 // works

val res = 7.unwrap() // doesn't work

println("=> result: " + res)
}
}

object Test2188 {
implicit def toJavaList[A: ClassTag](t:collection.Seq[A]):java.util.List[A] = java.util.Arrays.asList(t.toArray:_*)

val x: java.util.List[String] = List("foo")
}

object TestNumericWidening {
val y = 1
val x: java.lang.Long = y
}

// #2709
package foo2709 {
class A
class B

package object bar {
implicit def a2b(a: A): B = new B
}

package bar {
object test {
new A: B
}
}
}

// Problem with specs
object specsProblem {
println(implicitly[TypeTag[Class[_]]])
}

object Foo {
1.baa
}

0 comments on commit 94d80f1

Please sign in to comment.