Tweak tests for inferred implicits

This commit is contained in:
Som Snytt 2022-08-28 13:41:25 -07:00
parent 22531888cc
commit 1659fdcf0f
79 changed files with 375 additions and 75 deletions

View File

@ -199,7 +199,7 @@ package scala.async.run.toughtype {
}
object FunDep {
implicit def `Something to do with List`[W, S, R](implicit funDep: FunDep[W, S, R]) =
implicit def `Something to do with List`[W, S, R](implicit funDep: FunDep[W, S, R]): FunDep[W,List[S],W] =
new FunDep[W, List[S], W] {
def method(w: W, l: List[S]) = async {
val it = l.iterator

View File

@ -17,9 +17,10 @@ object Test {
}
trait Features {
implicit def implicitously = scala.language.implicitConversions
implicit def reflectively = scala.language.reflectiveCalls
implicit def postulously = scala.language.postfixOps
import languageFeature._
implicit def implicitously: implicitConversions = scala.language.implicitConversions
implicit def reflectively: reflectiveCalls = scala.language.reflectiveCalls
implicit def postulously: postfixOps = scala.language.postfixOps
}
@ -40,7 +41,9 @@ trait MinimalScalaTest extends Output with Features with Vigil {
if (throwables.nonEmpty) println(buffer.toString)
}
implicit def stringops(s: String) = new {
type Ops = AnyRef{def should[U](snippets: => U): U; def in[U](snippet: => U): scala.collection.mutable.IndexedSeq[_ >: Char with Throwable] with scala.collection.mutable.AbstractSeq[_ >: Char with Throwable] with scala.collection.mutable.Growable[Char with Throwable] with java.io.Serializable}
implicit def stringops(s: String): Ops = new {
def should[U](snippets: => U) = {
bufferPrintln(s + " should:")
@ -62,7 +65,8 @@ trait MinimalScalaTest extends Output with Features with Vigil {
}
implicit def objectops(obj: Any) = new {
type OOps = AnyRef{def mustBe(other: Any): Unit; def mustEqual(other: Any): Unit}
implicit def objectops(obj: Any): OOps = new {
def mustBe(other: Any) = assert(obj == other, s"$obj is not $other")
def mustEqual(other: Any) = mustBe(other)

View File

@ -87,6 +87,8 @@ scala> case class Bar(n: Int)
class Bar
scala> implicit def foo2bar(foo: Foo) = Bar(foo.n)
^
warning: Implicit definition should have explicit type (inferred Bar)
warning: 1 feature warning; for details, enable `:setting -feature` or `:replay -feature`
def foo2bar(foo: Foo): Bar

View File

@ -1055,7 +1055,7 @@ class ExecutionContextPrepare extends TestBase {
delegate.reportFailure(t)
}
implicit val ec = new PreparingExecutionContext
implicit val ec: ExecutionContext = new PreparingExecutionContext
def testOnComplete(): Unit = once {
done =>

View File

@ -37,8 +37,8 @@ object Test1579 {
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)
implicit def unwrap[C](q: Query[C]): C = q.value
implicit def invoker(q: Query[Column]): Invoker = new Invoker(q)
val q = new Query(new Column)
q.foo
@ -50,9 +50,9 @@ object Test1625 {
def unwrap() = x
}
implicit def byName[A](x: => A) = new Wrapped(x)
implicit def byName[A](x: => A): Wrapped = new Wrapped(x)
implicit def byVal[A](x: A) = x
implicit def byVal[A](x: A): A = x
def main(args: Array[String]) = {

View File

@ -16,4 +16,11 @@ implicits.scala:47: error: type mismatch;
implicits.scala:59: error: could not find implicit value for parameter x: Nothing
foo {
^
implicits.scala:34: warning: Implicit definition should have explicit type (inferred T)
implicit def select[T](t: HSome[T,_]) = t.head
^
implicits.scala:35: warning: Implicit definition should have explicit type (inferred L)
implicit def selectTail[L](t: HSome[_,L]) = t.tail
^
2 warnings
4 errors

View File

@ -1,5 +1,9 @@
override-final-implicit.scala:6: warning: Implicit definition should have explicit type (inferred Test.this.FooExtender)
override implicit def FooExtender(foo: String) = super.FooExtender(foo)
^
override-final-implicit.scala:6: error: cannot override final member:
final implicit def FooExtender(foo: String): Test.this.FooExtender (defined in class Implicits)
override implicit def FooExtender(foo: String) = super.FooExtender(foo)
^
1 warning
1 error

View File

@ -1,4 +1,8 @@
private-implicit-class.scala:6: error: method BarExtender in class ImplicitsPrivate cannot be accessed as a member of ImplicitsPrivate from class TestPrivate
override implicit def BarExtender(bar: Int) = super.BarExtender(bar) // error
^
private-implicit-class.scala:6: warning: Implicit definition should have explicit type
override implicit def BarExtender(bar: Int) = super.BarExtender(bar) // error
^
1 warning
1 error

View File

@ -4,5 +4,6 @@ object Y {
val a = new X
import a._
implicit val b : Int = 1
@annotation.nowarn
implicit val c = 2
}

View File

@ -2,4 +2,8 @@ t2206.scala:10: error: value f is not a member of o.A
Note: implicit method ax is not applicable here because it comes after the application point and it lacks an explicit result type
a.f()
^
t2206.scala:13: warning: Implicit definition should have explicit type (inferred o.AX)
implicit def ax(a: A) = new AX
^
1 warning
1 error

View File

@ -1,4 +1,8 @@
t2421b.scala:12: error: could not find implicit value for parameter aa: Test.F[Test.A]
f
^
t2421b.scala:10: warning: Implicit definition should have explicit type (inferred Test.F[X])
implicit def b[X <: B] = new F[X]()
^
1 warning
1 error

View File

@ -1,7 +1,7 @@
// for 2.7.x compatibility
object A {
implicit val one = 1
implicit val one: Int = 1
}
object Test {

View File

@ -3,4 +3,8 @@ t3006.scala:8: error: type mismatch;
required: Int
println(A(3) + "H")
^
t3006.scala:6: warning: Implicit definition should have explicit type (inferred Test.Foo)
implicit def aToFoo(x: A) = new Foo(x);
^
1 warning
1 error

View File

@ -1,4 +1,4 @@
t3346c.scala:60: error: value bar is not a member of Either[Int,String]
t3346c.scala:65: error: value bar is not a member of Either[Int,String]
did you mean map?
eii.bar
^

View File

@ -1,3 +1,5 @@
import annotation._
object Test extends App {
//
// An attempt to workaround scala/bug#2712, foiled by scala/bug#3346
@ -32,15 +34,18 @@ object Test extends App {
}
@nowarn
implicit def ToTCValue[M[_], A](ma: M[A])(implicit M0: TC[M]) = new TCValue[M, A] {
implicit val M = M0
implicit val M: TC[M] = M0
val self = ma
}
implicit def ToTCValueBin1[M[_, _], A, B](ma: M[A, B])(implicit M0: TC[({type λ[α]=M[A, α]})#λ]): TCValue[({type λ[α] = M[A, α]})#λ, B] = new TCValue[({type λ[α]=M[A, α]})#λ, B] {
@nowarn
implicit val M = M0
val self = ma
}
implicit def ToTCValueBin2[M[_, _], A, B](ma: M[A, B])(implicit M0: TC[({type λ[α]=M[α, B]})#λ]): TCValue[({type λ[α]=M[α, B]})#λ, A] = new TCValue[({type λ[α]=M[α, B]})#λ, A] {
@nowarn
implicit val M = M0
val self = ma
}

View File

@ -4,4 +4,20 @@ t3346i.scala:28: error: value a is not a member of Test.A[T]
t3346i.scala:29: error: value a is not a member of Test.A[Nothing]
(new A[Nothing]).a
^
t3346i.scala:16: warning: Implicit definition should have explicit type (inferred Implicit1[T])
implicit def implicit1[T <: Intermediate[_, _]](implicit b: Implicit2[T]) = new Implicit1[T](b)
^
t3346i.scala:18: warning: Implicit definition should have explicit type (inferred Implicit2[T])
implicit def implicit2alt1[T <: Intermediate[_ <: String, _]](implicit c: Implicit3[T]) = new Implicit2[T](c)
^
t3346i.scala:19: warning: Implicit definition should have explicit type (inferred Implicit2[T])
implicit def implicit2alt2[T <: Intermediate[_ <: Double, _]](implicit c: Implicit3[T]) = new Implicit2[T](c)
^
t3346i.scala:21: warning: Implicit definition should have explicit type (inferred Implicit3[T])
implicit def implicit3alt1[T <: Intermediate[_, _ <: Int]] = new Implicit3[T]()
^
t3346i.scala:22: warning: Implicit definition should have explicit type (inferred Implicit3[T])
implicit def implicit3alt2[T <: Intermediate[_ <: Double, _ <: AnyRef],X] = new Implicit3[T]()
^
5 warnings
2 errors

View File

@ -8,4 +8,23 @@ t4271.scala:11: error: value -> is not a member of Int
did you mean >>>?
3 -> 5
^
t4271.scala:3: warning: Implicit definition should have explicit type (inferred foo.Donotuseme.type)
implicit def Ensuring[A](x: A) = Donotuseme
^
t4271.scala:4: warning: Implicit definition should have explicit type (inferred foo.Donotuseme.type)
implicit def doubleWrapper(x: Int) = Donotuseme
^
t4271.scala:5: warning: Implicit definition should have explicit type (inferred foo.Donotuseme.type)
implicit def floatWrapper(x: Int) = Donotuseme
^
t4271.scala:6: warning: Implicit definition should have explicit type (inferred foo.Donotuseme.type)
implicit def intWrapper(x: Int) = Donotuseme
^
t4271.scala:7: warning: Implicit definition should have explicit type (inferred foo.Donotuseme.type)
implicit def longWrapper(x: Int) = Donotuseme
^
t4271.scala:8: warning: Implicit definition should have explicit type (inferred foo.Donotuseme.type)
implicit def ArrowAssoc[A](x: A) = Donotuseme
^
6 warnings
3 errors

View File

@ -4,4 +4,20 @@ and method aFunc in object ImplicitConvAmbiguity2 of type [A](a: ImplicitConvAm
match argument types (Float)
val x = aFunc(4F)
^
t4457_1.scala:11: warning: Implicit definition should have explicit type (inferred ImplicitConvAmbiguity2.NE[Float])
implicit def conv1(i: Float) = new NE[Float]
^
t4457_1.scala:12: warning: Implicit definition should have explicit type (inferred ImplicitConvAmbiguity2.N[java.util.TooManyListenersException])
implicit def conv3(op: AA[java.util.TooManyListenersException]) = new N[java.util.TooManyListenersException]
^
t4457_1.scala:13: warning: Implicit definition should have explicit type (inferred ImplicitConvAmbiguity2.N[Float])
implicit def conv4(op: AA[Float]) = new N[Float]
^
t4457_1.scala:14: warning: Implicit definition should have explicit type (inferred ImplicitConvAmbiguity2.NZ[Float])
implicit def conv7(i: Float) = new NZ[Float]
^
t4457_1.scala:15: warning: Implicit definition should have explicit type (inferred ImplicitConvAmbiguity2.N[java.util.GregorianCalendar])
implicit def conv5(e: BB[java.util.GregorianCalendar]) = new N[java.util.GregorianCalendar]
^
5 warnings
1 error

View File

@ -10,4 +10,20 @@ and method aFunc in object ImplicitConvAmbiguity2 of type [A](a: ImplicitConvAm
match argument types (Float)
bFunc(aFunc(4F))
^
t4457_2.scala:11: warning: Implicit definition should have explicit type (inferred ImplicitConvAmbiguity2.NE[Float])
implicit def conv1(i: Float) = new NE[Float]
^
t4457_2.scala:12: warning: Implicit definition should have explicit type (inferred ImplicitConvAmbiguity2.N[java.util.TooManyListenersException])
implicit def conv3(op: AA[java.util.TooManyListenersException]) = new N[java.util.TooManyListenersException]
^
t4457_2.scala:13: warning: Implicit definition should have explicit type (inferred ImplicitConvAmbiguity2.N[Float])
implicit def conv4(op: AA[Float]) = new N[Float]
^
t4457_2.scala:14: warning: Implicit definition should have explicit type (inferred ImplicitConvAmbiguity2.NZ[Float])
implicit def conv7(i: Float) = new NZ[Float]
^
t4457_2.scala:15: warning: Implicit definition should have explicit type (inferred ImplicitConvAmbiguity2.N[java.util.GregorianCalendar])
implicit def conv5(e: BB[java.util.GregorianCalendar]) = new N[java.util.GregorianCalendar]
^
5 warnings
2 errors

View File

@ -1,4 +1,8 @@
t4568.scala:8: error: recursive method isSubListOf needs result type
case h :: t => y.contains(h) && (t.isSubListOf(y.drop(y.indexOf(h) + 1)))
^
t4568.scala:2: warning: Implicit definition should have explicit type (inferred SubList.SubListable[A])
implicit def sublistable[A](x: List[A]) = new SubListable(x)
^
1 warning
1 error

View File

@ -1,4 +1,8 @@
t4889.scala:19: error: could not find implicit value for parameter ma1: t4889.MatrixAdder[Int,[S]t4889.SparseMatrix[S]]
m1.foo
^
t4889.scala:14: warning: Implicit definition should have explicit type (inferred t4889.MatrixAdder[S,R])
implicit def adderImplicit[S, R[s] <: Matrix[s, R]] = new MatrixAdder[S, R] {
^
1 warning
1 error

View File

@ -1,4 +1,8 @@
t5728.scala:3: error: implicit classes must accept exactly one primary constructor parameter
implicit class Foo
^
t5728.scala:5: warning: Implicit definition should have explicit type (inferred Test.Foo)
implicit def Foo = new Foo
^
1 warning
1 error

View File

@ -7,4 +7,11 @@ Note that implicit conversions are not applicable because they are ambiguous:
are possible conversion functions from StringContext to ?{def q: ?}
println(q"a")
^
t6436.scala:2: warning: Implicit definition should have explicit type (inferred AnyRef{def q: Nothing})
implicit def foo1(ctx: StringContext) = new { def q = ??? }
^
t6436.scala:3: warning: Implicit definition should have explicit type (inferred AnyRef{def q: Nothing})
implicit def foo2(ctx: StringContext) = new { def q = ??? }
^
2 warnings
1 error

View File

@ -7,4 +7,11 @@ Note that implicit conversions are not applicable because they are ambiguous:
are possible conversion functions from StringContext to ?{def q: ?}
println(StringContext("a").q())
^
t6436b.scala:2: warning: Implicit definition should have explicit type (inferred AnyRef{def q: Nothing})
implicit def foo1(ctx: StringContext) = new { def q = ??? }
^
t6436b.scala:3: warning: Implicit definition should have explicit type (inferred AnyRef{def q: Nothing})
implicit def foo2(ctx: StringContext) = new { def q = ??? }
^
2 warnings
1 error

View File

@ -1,3 +1,6 @@
t6567.scala:8: warning: Implicit definition should have explicit type (inferred B)
implicit def a2b(a: A) = new B
^
t6567.scala:10: warning: Suspicious application of an implicit view (Test.this.a2b) in the argument to Option.apply.
Option[B](a)
^
@ -6,5 +9,5 @@ t6567.scala:12: warning: Suspicious application of an implicit view (Test.this.a
^
warning: 1 feature warning; re-run with -feature for details
error: No warnings can be incurred under -Werror.
3 warnings
4 warnings
1 error

View File

@ -10,4 +10,8 @@ t6667.scala:9: error: ambiguous implicit values:
match expected type C
implicitly[C] // ambiguity reported, rather than falling back to C.companion
^
t6667.scala:3: warning: Implicit definition should have explicit type (inferred C)
implicit def companion = new C
^
1 warning
2 errors

View File

@ -4,7 +4,7 @@ object C {
}
object Test {
implicit val inScope1, inScope2 = new C
implicit val inScope1, inScope2: C = new C
implicitly[C]: Unit // C.companion was used; whereas the ambiguity should abort the implicit search.
implicitly[C] // ambiguity reported, rather than falling back to C.companion
}

View File

@ -16,4 +16,8 @@ t692.scala:14: error: class Foo takes type parameters
t692.scala:19: error: class Foo takes type parameters
class Bar[A <: Foo](implicit tpeA : Type[A]) extends Foo;
^
t692.scala:11: warning: Implicit definition should have explicit type (inferred test3.this.FooType)
implicit def typeOfFoo = FooType();
^
1 warning
6 errors

View File

@ -1,4 +1,11 @@
t712.scala:10: error: overloaded method coerce needs result type
implicit def coerce(p : ParentImpl) = p.self;
^
t712.scala:3: warning: Implicit definition should have explicit type (inferred A.this.Node)
implicit def coerce(n : NodeImpl) = n.self;
^
t712.scala:10: warning: Implicit definition should have explicit type
implicit def coerce(p : ParentImpl) = p.self;
^
2 warnings
1 error

View File

@ -4,4 +4,11 @@ t7131.scala:21: error: type mismatch;
Note: implicit method convertToSimpleMappable is not applicable here because it comes after the application point and it lacks an explicit result type
x.value.map(f)
^
t7131.scala:28: warning: Implicit definition should have explicit type (inferred ObservableValue.TraversableMappable[T,Container])
implicit def convertToTraversableMappable[T, Container[X] <: Traversable[X]](x: ObservableValue[Container[T]]) =
^
t7131.scala:43: warning: Implicit definition should have explicit type (inferred ObservableValue.NestedMappable[T,Container])
implicit def convertToSimpleMappable[T, Container[X] <: ObservableValue.HasMap[X, Container]](x: ObservableValue[Container[T]]) =
^
2 warnings
1 error

View File

@ -3,4 +3,11 @@ t729.scala:20: error: type mismatch;
required: ScalaParserAutoEdit.this.NodeImpl(in trait ScalaParserAutoEdit)
val yyy : NodeImpl = link.from;
^
t729.scala:3: warning: Implicit definition should have explicit type (inferred Parser.this.Node)
implicit def coerce(n : NodeImpl) = n.self;
^
t729.scala:14: warning: Implicit definition should have explicit type (inferred ScalaParserAutoEdit.this.Node)
implicit def coerce(node : NodeImpl) = node.self;
^
2 warnings
1 error

View File

@ -13,4 +13,11 @@ t8322.scala:19: error: type mismatch;
required: scala.util.Either[?,?]
Right(0).right.flatMap(_ => new String())
^
t8322.scala:15: warning: Implicit definition should have explicit type (inferred Writes[Seq[E]])
implicit def rw[E] = Writes[Seq[E]] { _ => "" }
^
t8322.scala:17: warning: Implicit definition should have explicit type
implicit def wr[E] = jw(implicitly, implicitly)
^
2 warnings
3 errors

View File

@ -13,3 +13,14 @@ class C extends B {
override def f: Option[String] = Some("goodbye, cruel world")
override def remove(): Unit = println("removed! (not really)")
}
trait T { def f: Object }
class K extends T { def f = "" }
object K {
val k = new K
val s: Any = k.f
}
trait U extends T { def f = "" }
trait V { var v: Any }
trait W extends V { var v = "" }

View File

@ -23,7 +23,7 @@ package a {
def apply(x: Double): Meter = new Meter(x)
implicit val boxings = new BoxingConversions[Meter, Double] {
implicit val boxings: BoxingConversions[Meter, Double] = new BoxingConversions[Meter, Double] {
def box(x: Double) = new Meter(x)
def unbox(m: Meter) = m.underlying
}
@ -35,7 +35,7 @@ package a {
override def toString = unbox.toString+"ft"
}
object Foot {
implicit val boxings = new BoxingConversions[Foot, Double] {
implicit val boxings: BoxingConversions[Foot, Double] = new BoxingConversions[Foot, Double] {
def box(x: Double) = new Foot(x)
def unbox(m: Foot) = m.unbox
}

View File

@ -20,7 +20,7 @@ package a {
private[a] trait MeterArg
implicit val boxings = new BoxingConversions[Meter, Double] {
implicit val boxings: BoxingConversions[Meter, Double] = new BoxingConversions[Meter, Double] {
def box(x: Double) = new Meter(x)
def unbox(m: Meter) = m.underlying
}
@ -32,7 +32,7 @@ package a {
override def toString = unbox.toString+"ft"
}
object Foot {
implicit val boxings = new BoxingConversions[Foot, Double] {
implicit val boxings: BoxingConversions[Foot, Double] = new BoxingConversions[Foot, Double] {
def box(x: Double) = new Foot(x)
def unbox(m: Foot) = m.unbox
}

View File

@ -7,7 +7,7 @@ object Test extends App {
val lazee = reify {
class C {
lazy val x = 2
implicit lazy val y = 3
implicit lazy val y: Int = 3
}
val c = new C()
import c._

View File

@ -9,7 +9,7 @@ object Test {
def *(newUnit: Unit) = Measure(scalar, newUnit)
}
implicit def double2Measure(scalar: Double) =
implicit def double2Measure(scalar: Double): Measure =
Measure(scalar, NoUnit)

View File

@ -2,7 +2,7 @@ import scala.language.implicitConversions
object A {
object B {
implicit def int2string(x: Int) = "["+x.toString+"]"
implicit def int2string(x: Int): String = "["+x.toString+"]"
}
}

View File

@ -1,6 +1,6 @@
import scala.language.experimental.macros
object Test extends App {
implicit val x = 42
implicit val x: Int = 42
def foo(implicit x: Int): Unit = macro Impls.foo
foo
}

View File

@ -5,9 +5,9 @@ class CustomClass
trait MyTC[A]
object MyTC {
implicit val forInt = new MyTC[Int] {}
implicit def forList[A](implicit a: Derivation[MyTC[A]]) = new MyTC[List[A]] {}
implicit def forCustomClass(implicit a: Derivation[MyTC[List[Boolean]]]) = new MyTC[CustomClass] {}
implicit val forInt: MyTC[Int] = new MyTC[Int] {}
implicit def forList[A](implicit a: Derivation[MyTC[A]]): MyTC[List[A]] = new MyTC[List[A]] {}
implicit def forCustomClass(implicit a: Derivation[MyTC[List[Boolean]]]): MyTC[CustomClass] = new MyTC[CustomClass] {}
}
object Test extends App {

View File

@ -3,7 +3,7 @@ import scala.language.implicitConversions
import scala.reflect.runtime.universe._
class C {
implicit val v = new C
implicit val v: C = new C
implicit def d(x: C)(implicit c: C): Int = ???
implicit class X(val x: Int)
}

View File

@ -2,7 +2,7 @@
scala> def showInt(implicit x: Int) = println(x)
def showInt(implicit x: Int): Unit
scala> object IntHolder { implicit val myInt = 5 }
scala> object IntHolder { implicit val myInt: Int = 5 }
object IntHolder
scala> import IntHolder.myInt

View File

@ -11,7 +11,7 @@ object Test extends ReplTest {
def code = """
|def showInt(implicit x: Int) = println(x)
|object IntHolder { implicit val myInt = 5 }
|object IntHolder { implicit val myInt: Int = 5 }
|import IntHolder.myInt
|showInt
|class A; showInt

View File

@ -11,7 +11,6 @@ warning: 1 deprecation (since 2.11.0); for details, enable `:setting -deprecatio
val res0: $r.global.noSelfType.type = private val _ = _
scala> val tp = ArrayClass[scala.util.Random] // magic with tags
warning: 1 feature warning; for details, enable `:setting -feature` or `:replay -feature`
val tp: $r.global.Type = Array[scala.util.Random]
scala> tp.memberType(Array_apply) // evidence

View File

@ -11,7 +11,6 @@ warning: 1 deprecation (since 2.11.0); for details, enable `:setting -deprecatio
val res0: $r.global.noSelfType.type = private val _ = _
scala> val tp = ArrayClass[scala.util.Random] // magic with tags
warning: 1 feature warning; for details, enable `:setting -feature` or `:replay -feature`
val tp: $r.global.Type = Array[scala.util.Random]
scala> tp.memberType(Array_apply) // evidence

View File

@ -4,11 +4,11 @@ object Test extends App {
def mkAssoc[K, V0](k: K, v0: V0): Assoc[k.type] { type V = V0 } = new Assoc[k.type] {type V = V0 ; val v = v0}
def lookup[K](k: K)(implicit a: Assoc[k.type]): a.V = a.v
implicit def firstAssoc = mkAssoc(1, "Panda!")
implicit def secondAssoc = mkAssoc(2, "Kitty!")
implicit def firstAssoc: Assoc[1] { type V = String } = mkAssoc(1, "Panda!")
implicit def secondAssoc: Assoc[2] { type V = String } = mkAssoc(2, "Kitty!")
implicit def ageAssoc = mkAssoc("Age", 3)
implicit def nmAssoc = mkAssoc("Name", "Jane")
implicit def ageAssoc: Assoc["Age"] { type V = Int } = mkAssoc("Age", 3)
implicit def nmAssoc: Assoc["Name"] { type V = String } = mkAssoc("Name", "Jane")
assert(lookup(1) == "Panda!")
assert(lookup(2) == "Kitty!")

View File

@ -1,7 +1,7 @@
case class T1(source: String)
object T1 {
implicit def T1FromT2(implicit t2: T2) = new T1(t2.source)
implicit def T1FromT2(implicit t2: T2): T1 = new T1(t2.source)
}
case class T2(source: String)
@ -10,7 +10,7 @@ object A {
def requireT1(implicit t1: T1) = t1
object B1 {
implicit val t2_b1 = new T2("from B1")
implicit val t2_b1: T2 = new T2("from B1")
requireT1
}

View File

@ -2,9 +2,8 @@
import scala.language.{ implicitConversions, postfixOps, reflectiveCalls }
object Test
{
implicit def x[A](a: A) = new { def xx = a }
object Test {
implicit def x[A](a: A): AnyRef{def xx: A} = new { def xx = a }
def main(args: Array[String]): Unit = {
val r1 = 12 xx;

View File

@ -1,7 +1,7 @@
// for 2.7.x compatibility
object A {
implicit val one = 1
implicit val one: Int = 1
}
object Test extends App {

View File

@ -11,7 +11,7 @@ object Test extends App {
def create(v: A): Basket[A,B]
}
implicit val bf = new BasketFactory[Int,TARInt] {
implicit val bf: BasketFactory[Int,TARInt] = new BasketFactory[Int,TARInt] {
def create(v: Int): Basket[Int,TARInt] = new Basket[Int, TARInt]{}
}

View File

@ -47,9 +47,9 @@ class FilterMapFixed[A, Repr <% IterableOps[A, Iterable, _]](a: Repr) {
}
object MyEnhancements {
implicit def toQS[Coll](a: Coll) = new QuickSort(a)
implicit def toFM[Coll](a: Coll) = new FilterMap(a)
implicit def toFM2[A, Repr <% IterableOps[A, Iterable, _]](a: Repr) = new FilterMapFixed(a)
implicit def toQS[Coll](a: Coll): QuickSort[Coll] = new QuickSort(a)
implicit def toFM[Coll](a: Coll): FilterMap[Coll] = new FilterMap(a)
implicit def toFM2[A, Repr <% IterableOps[A, Iterable, _]](a: Repr): FilterMapFixed[A,Repr] = new FilterMapFixed(a)
}
object Test extends App {

View File

@ -4,11 +4,11 @@ import scala.language.reflectiveCalls
object Test extends App {
trait Foo[A]
implicit def fooString: Foo[String] = null
implicit def value[A](implicit foo: Foo[A]) = 5
implicit def value[A](implicit foo: Foo[A]): Int = 5
println(implicitly[Int])
implicit def conversion[A](x: Int)(implicit foo: Foo[A]) = new {
implicit def conversion[A](x: Int)(implicit foo: Foo[A]): AnyRef{def aMethod: Int} = new {
def aMethod = 5
}
println(1.aMethod)

View File

@ -1 +0,0 @@
x

View File

@ -3,7 +3,7 @@ import scala.language.implicitConversions
object Test extends App {
trait Fundep[T, U] { def u(t: T): U }
class C { def y = "x" }
implicit val FundepStringC = new Fundep[String, C]{ def u(t: String) = new C }
implicit val FundepStringC: Fundep[String,C] = new Fundep[String, C]{ def u(t: String) = new C }
implicit def foo[T, U](x: T)(implicit y: Fundep[T, U]): U = y.u(x)
println("x".y)
assert("x".y == "x")
}

View File

@ -5,7 +5,7 @@ import scala.reflect.runtime.universe._
object Test extends App {
class A[T]
class B[T]
implicit def foo[T: TypeTag](a: A[T])(implicit b: B[T]) = new { def baz = typeOf[T] }
implicit def foo[T: TypeTag](a: A[T])(implicit b: B[T]): AnyRef{def baz: reflect.runtime.universe.Type} = new { def baz = typeOf[T] }
implicit def bar[T <: Int]: B[T] = new B[T]()
println(new A[Int]().baz)
}

View File

@ -11,7 +11,7 @@ object Test extends App {
override def toString = value.toString;
}
implicit def conversions(x: Value) = new {
implicit def conversions(x: Value): AnyRef { def toInt: Int } = new {
def toInt =
x match {
case Num(n) => n

View File

@ -4,7 +4,7 @@ import scala.tools.reflect.Eval
object Test extends App {
reify {
class C {
implicit lazy val x = 2
implicit lazy val x: Int = 2
def y = implicitly[Int]
}

View File

@ -1,7 +1,9 @@
import scala.annotation.nowarn
import scala.language.reflectiveCalls
import scala.language.implicitConversions
object Test extends App {
@nowarn // the inferred type includes the default arg, which can't be written explicitly
implicit def doubleWithApproxEquals(d: Double) = new {
def ~==(v: Double, margin: Double = 0.001): Boolean =
math.abs(d - v) < margin
@ -10,3 +12,11 @@ object Test extends App {
assert(math.abs(-4.0) ~== (4.0, 0.001))
assert(math.abs(-4.0) ~== 4.0)
}
/*
was:
Exception in thread "main" java.lang.IllegalAccessError: tried to access field illegal_access_error_test_case$.reflParams$Cache2 from class illegal_access_error_test_case$delayedInit$body
at illegal_access_error_test_case$delayedInit$body.<clinit>(illegal_access_error_test_case.scala:8)
at illegal_access_error_test_case$.<init>(illegal_access_error_test_case.scala:1)
at illegal_access_error_test_case$.<clinit>(illegal_access_error_test_case.scala)
at illegal_access_error_test_case.main(illegal_access_error_test_case.scala)
*/

View File

@ -1,4 +1,5 @@
object Test {
implicit val foo = language.dynamics
import languageFeature._
implicit val foo: dynamics = language.dynamics
def main(args: Array[String]): Unit = ()
}

View File

@ -7,8 +7,8 @@ object Test extends App {
case class R[+T](s: String) { def x() = println(s) }
// Implicits in contention; StringR is nested to avoid ambiguity
object R { implicit val StringR = R[String]("A") }
implicit val Default = R[Any]("B")
object R { implicit val StringR: R[String] = R[String]("A") }
implicit val Default: R[Any] = R[Any]("B")
class B() extends Dynamic {
def selectDynamic[T](f: String)(implicit r: R[T]): Unit = r.x()

View File

@ -4,7 +4,7 @@
import scala.language.{ implicitConversions }
abstract class BaseList {
type Node <: BaseNodeImpl
implicit def convertNode(ni : BaseNodeImpl) = ni.asInstanceOf[Node];
implicit def convertNode(ni : BaseNodeImpl): Node = ni.asInstanceOf[Node];
abstract class BaseNodeImpl
}
abstract class LinkedList extends BaseList {
@ -33,7 +33,7 @@ trait Matcher extends PrecedenceParser {
trait NodeImpl4 extends super.NodeImpl3
type Matchable <: Node with MatchableImpl0
implicit def convertMatchable(m : MatchableImpl0) = m.asInstanceOf[Matchable]
implicit def convertMatchable(m : MatchableImpl0): Matchable = m.asInstanceOf[Matchable]
trait MatchableImpl0 extends NodeImpl4 {
override def chop : Node = {
Console.println("passed"); super.chop;

View File

@ -13,8 +13,8 @@ object Test extends App {
def lookup(k: String)(implicit assoc: Assoc[k.type]): assoc.V = assoc.value
implicit def nameAssoc = mkAssoc("Name", "Mary")
implicit def ageAssoc = mkAssoc("Age", 23)
implicit def nameAssoc: Assoc["Name"] { type V = String } = mkAssoc("Name", "Mary")
implicit def ageAssoc: Assoc["Age"] { type V = Int } = mkAssoc("Age", 23)
assert((lookup("Name"): String) == "Mary")
assert((lookup("Age"): Int) == 23)

View File

@ -103,8 +103,8 @@ trait ParserIdioms extends Parsers with Idioms {
// TODO: how can parserIdiom(curry2(_)) be omitted?
def expr: Parser[Expr] = parserIdiomFun(curry2(Plus)) <| num <> num |>
implicit def curry2[s, t, u](fun: (s, t) => u)(a: s)(b: t) = fun(a, b)
implicit def curry3[r, s, t, u](fun: (r, s, t) => u)(a: r)(b: s)(c: t) = fun(a, b, c)
implicit def curry2[s, t, u](fun: (s, t) => u)(a: s)(b: t): u = fun(a, b)
implicit def curry3[r, s, t, u](fun: (r, s, t) => u)(a: r)(b: s)(c: t): u = fun(a, b, c)
}
object Test extends ParserIdioms with App {

View File

@ -10,7 +10,7 @@ import java.io.{Console => _, _}
class SourceTest {
private implicit val `our codec` = Codec.UTF8
private implicit val `our codec`: Codec = Codec.UTF8
private val charSet = Codec.UTF8.charSet.name
private def sampler = """

View File

@ -10,11 +10,11 @@ class AbstractFileClassLoaderTest {
import scala.reflect.io._
import scala.io.Source
import scala.io.Codec.UTF8
import scala.io.Codec, Codec.UTF8
import scala.reflect.io.Streamable
import java.net.{ URLClassLoader, URL }
implicit def `we love utf8` = UTF8
implicit def `we love utf8`: Codec = UTF8
implicit class `abs file ops`(f: AbstractFile) {
def writeContent(s: String): Unit = Streamable.closing(f.bufferedOutput)(os => os write s.getBytes(UTF8.charSet))
}

View File

@ -2,7 +2,7 @@
object Test extends App {
def assertEquals(a: Any, b: Any): Unit = { assert(a == b, s"$a != $b") }
implicit val x = 42
implicit val x: Int = 42
@explorer object C
// @Test def toplevel: Unit =

View File

@ -31,8 +31,8 @@ trait Generators {
} yield mutable.TreeMap(keys zip values: _*)
}
implicit def arbRedBlackTree[A: Arbitrary: Ordering, B: Arbitrary] = Arbitrary(genRedBlackTree[A, B])
implicit def arbTreeMap[A: Arbitrary: Ordering, B: Arbitrary] = Arbitrary(genTreeMap[A, B])
implicit def arbRedBlackTree[A: Arbitrary: Ordering, B: Arbitrary]: Arbitrary[RB.Tree[A,B]] = Arbitrary(genRedBlackTree[A, B])
implicit def arbTreeMap[A: Arbitrary: Ordering, B: Arbitrary]: Arbitrary[mutable.TreeMap[A,B]] = Arbitrary(genTreeMap[A, B])
}
object RedBlackTreeProperties extends Properties("mutable.RedBlackTree") with Generators {
@ -218,7 +218,7 @@ object MutableTreeMapProjectionProperties extends Properties("mutable.TreeMapPro
type K = String
type V = Int
implicit val ord = implicitly[Ordering[K]]
private val ord = implicitly[Ordering[K]]
def in(key: K, from: Option[K], until: Option[K]) =
from.fold(true)(_ <= key) && until.fold(true)(_ > key)

View File

@ -117,7 +117,7 @@ object MutableTreeSetProperties extends Properties("mutable.TreeSet") {
object MutableTreeSetProjectionProperties extends Properties("mutable.TreeSetProjection") {
type K = String
implicit val ord = implicitly[Ordering[K]]
private val ord = implicitly[Ordering[K]]
def in(key: K, from: Option[K], until: Option[K]) =
from.fold(true)(_ <= key) && until.fold(true)(_ > key)

View File

@ -267,8 +267,8 @@ trait ArbitraryTreesAndNames {
def genTreeIsTypeWrapped(size: Int) =
for(tit <- genTreeIsType(size)) yield TreeIsType(tit)
implicit val liftTreeIsTerm = Liftable[TreeIsTerm] { _.tree }
implicit val liftTreeIsType = Liftable[TreeIsType] { _.tree }
implicit val liftTreeIsTerm: Liftable[TreeIsTerm] = Liftable[TreeIsTerm] { _.tree }
implicit val liftTreeIsType: Liftable[TreeIsType] = Liftable[TreeIsType] { _.tree }
implicit def treeIsTerm2tree(tit: TreeIsTerm): Tree = tit.tree
implicit def treeIsType2tree(tit: TreeIsType): Tree = tit.tree

View File

@ -12,7 +12,7 @@ object TreeMapTest extends Properties("TreeMap") {
keys <- listOf(arbitrary[A])
values <- listOfN(keys.size, arbitrary[B])
} yield TreeMap(keys zip values: _*)
implicit def arbTreeMap[A : Arbitrary : Ordering, B : Arbitrary] = Arbitrary(genTreeMap[A, B])
implicit def arbTreeMap[A : Arbitrary : Ordering, B : Arbitrary]: Arbitrary[TreeMap[A, B]] = Arbitrary(genTreeMap[A, B])
property("foreach/iterator consistency") = forAll { (subject: TreeMap[Int, String]) =>
val it = subject.iterator

View File

@ -1 +1,10 @@
newSource:10: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.diagrams.T)
object E { implicit def eToT(e: E) = new T }
^
newSource:18: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.diagrams.E)
object X { implicit def xToE(x: X) = new E}
^
newSource:21: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.diagrams.E)
object Z { implicit def zToE(z: Z) = new E}
^
Done.

View File

@ -1 +1,7 @@
newSource:30: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.diagrams.T)
implicit def eToT(e: E) = new T
^
newSource:31: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.diagrams.A)
implicit def eToA(e: E) = new A { }
^
Done.

View File

@ -1 +1,7 @@
newSource:70: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.ambiguating.X[T])
implicit def AtoX[T](a: A[T]) = new X[T]
^
newSource:71: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.ambiguating.Z[T])
implicit def AtoZ[T](a: A[T]) = new Z[T]
^
Done.

View File

@ -1 +1,19 @@
newSource:36: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.base.EnrichedA[V])
implicit def enrichA0[V](a: A[V]) = new EnrichedA(a)
^
newSource:37: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.base.NumericA[ZBUR])
implicit def enrichA1[ZBUR: Numeric](a: A[ZBUR]) = new NumericA[ZBUR](a)
^
newSource:38: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.base.IntA)
implicit def enrichA2(a: A[Int]) = new IntA(a)
^
newSource:39: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.base.GtColonDoubleA)
implicit def enrichA3(a: A[T] forSome { type T <: Double }) = new GtColonDoubleA(a)
^
newSource:42: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.base.MyNumericA[Z])
implicit def enrichA6[Z: MyNumeric](a: A[Z]) = new MyNumericA[Z](a)
^
newSource:44: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.base.ManifestA[H] with scala.test.scaladoc.implicits.base.MyTraversableOps[H])
implicit def enrichA7[H <: Double : Manifest](a: A[H]) = new ManifestA[H](a) with MyTraversableOps[H] { def convToTraversableOps(x: H): H = sys.error("no") }
^
Done.

View File

@ -1 +1,16 @@
newSource:22: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.Implicit1[T])
implicit def implicit1[T <: Intermediate[_, _]](implicit b: Implicit2[T]) = new Implicit1[T](b)
^
newSource:24: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.Implicit2[T])
implicit def implicit2alt1[T <: Intermediate[_ <: String, _]](implicit c: Implicit3[T]) = new Implicit2[T](c)
^
newSource:25: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.Implicit2[T])
implicit def implicit2alt2[T <: Intermediate[_ <: Double, _]](implicit c: Implicit3[T]) = new Implicit2[T](c)
^
newSource:27: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.Implicit3[T])
implicit def implicit3alt1[T <: Intermediate[_, _ <: Int]] = new Implicit3[T]()
^
newSource:28: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.Implicit3[T])
implicit def implicit3alt2[T <: Intermediate[_ <: Double, _ <: AnyRef],X] = new Implicit3[T]()
^
Done.

View File

@ -1 +1,49 @@
newSource:13: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.typeclasses.B[Numeric[T]])
implicit def convertNumeric [T: Numeric] (a: A[T]) = new B(implicitly[Numeric[T]])
^
newSource:14: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.typeclasses.B[Integral[T]])
implicit def convertIntegral [T: Integral] (a: A[T]) = new B(implicitly[Integral[T]])
^
newSource:15: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.typeclasses.B[Fractional[T]])
implicit def convertFractional [T: Fractional] (a: A[T]) = new B(implicitly[Fractional[T]])
^
newSource:16: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.typeclasses.B[Manifest[T]])
implicit def convertManifest [T: Manifest] (a: A[T]) = new B(implicitly[Manifest[T]])
^
newSource:17: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.typeclasses.B[reflect.ClassManifest[T]])
implicit def convertClassManifest [T: ClassManifest] (a: A[T]) = new B(implicitly[ClassManifest[T]])
^
newSource:18: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.typeclasses.B[OptManifest[T]])
implicit def convertOptManifest [T: OptManifest] (a: A[T]) = new B(implicitly[OptManifest[T]])
^
newSource:19: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.typeclasses.B[scala.reflect.ClassTag[T]])
implicit def convertClassTag [T: ClassTag] (a: A[T]) = new B(implicitly[ClassTag[T]])
^
newSource:20: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.typeclasses.B[reflect.runtime.universe.TypeTag[T]])
implicit def convertTypeTag [T: TypeTag] (a: A[T]) = new B(implicitly[TypeTag[T]])
^
newSource:29: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.typeclasses.B[scala.test.scaladoc.implicits.typeclasses.A.K[T]])
implicit def convertK [T: K] (a: A[T]) = new B(implicitly[K[T]])
^
newSource:30: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.typeclasses.B[scala.test.scaladoc.implicits.typeclasses.A.L[T]])
implicit def convertL [T: L] (a: A[T]) = new B(implicitly[L[T]])
^
newSource:31: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.typeclasses.B[scala.test.scaladoc.implicits.typeclasses.A.M[T]])
implicit def convertM [T: M] (a: A[T]) = new B(implicitly[M[T]])
^
newSource:32: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.typeclasses.B[scala.test.scaladoc.implicits.typeclasses.A.N[T]])
implicit def convertN [T: N] (a: A[T]) = new B(implicitly[N[T]])
^
newSource:33: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.typeclasses.B[scala.test.scaladoc.implicits.typeclasses.A.O[T]])
implicit def convertO [T: O] (a: A[T]) = new B(implicitly[O[T]])
^
newSource:34: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.typeclasses.B[scala.test.scaladoc.implicits.typeclasses.A.P[T]])
implicit def convertP [T: P] (a: A[T]) = new B(implicitly[P[T]])
^
newSource:35: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.typeclasses.B[scala.test.scaladoc.implicits.typeclasses.A.Q[T]])
implicit def convertQ [T: Q] (a: A[T]) = new B(implicitly[Q[T]])
^
newSource:36: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.typeclasses.B[scala.test.scaladoc.implicits.typeclasses.A.R[T]])
implicit def convertR [T: R] (a: A[T]) = new B(implicitly[R[T]])
^
Done.

View File

@ -1 +1,4 @@
newSource:63: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.implicits.shadowing.Z[T])
implicit def AtoZ[T](a: A[T]) = new Z[T]
^
Done.

View File

@ -1 +1,7 @@
newSource:8: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.variable.expansion.C)
implicit def aToC(a: A) = new C
^
newSource:9: warning: Implicit definition should have explicit type (inferred scala.test.scaladoc.variable.expansion.E with scala.test.scaladoc.variable.expansion.F)
implicit def aToE(a: A) = new E with F
^
Done.

View File

@ -9,7 +9,7 @@ object TestCtxFns {
def puts[T](t: T): Unit = logs += t.toString
}
implicit val ctx = new TestContext
implicit val ctx: TestContext = new TestContext
def test1: Unit = {
puts(23)(ctx)