Skip to content

Commit

Permalink
Tweak tests for inferred implicits
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Aug 29, 2022
1 parent 0af4ed8 commit ac5a670
Show file tree
Hide file tree
Showing 79 changed files with 375 additions and 75 deletions.
2 changes: 1 addition & 1 deletion test/async/jvm/toughtype.scala
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions test/files/jvm/future-spec/main.scala
Expand Up @@ -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
}


Expand All @@ -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:")
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions test/files/jvm/interpreter.check
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/files/jvm/scala-concurrent-tck.scala
Expand Up @@ -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 =>
Expand Down
8 changes: 4 additions & 4 deletions test/files/neg/implicit-log.scala
Expand Up @@ -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
Expand All @@ -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]) = {

Expand Down
7 changes: 7 additions & 0 deletions test/files/neg/implicits.check
Expand Up @@ -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
4 changes: 4 additions & 0 deletions test/files/neg/override-final-implicit.check
@@ -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
4 changes: 4 additions & 0 deletions test/files/neg/private-implicit-class.check
@@ -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
1 change: 1 addition & 0 deletions test/files/neg/t1038.scala
Expand Up @@ -4,5 +4,6 @@ object Y {
val a = new X
import a._
implicit val b : Int = 1
@annotation.nowarn
implicit val c = 2
}
4 changes: 4 additions & 0 deletions test/files/neg/t2206.check
Expand Up @@ -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
4 changes: 4 additions & 0 deletions test/files/neg/t2421b.check
@@ -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
2 changes: 1 addition & 1 deletion test/files/neg/t2866.scala
@@ -1,7 +1,7 @@
// for 2.7.x compatibility

object A {
implicit val one = 1
implicit val one: Int = 1
}

object Test {
Expand Down
4 changes: 4 additions & 0 deletions test/files/neg/t3006.check
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/files/neg/t3346c.check
@@ -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
^
Expand Down
7 changes: 6 additions & 1 deletion test/files/neg/t3346c.scala
@@ -1,3 +1,5 @@
import annotation._

object Test extends App {
//
// An attempt to workaround scala/bug#2712, foiled by scala/bug#3346
Expand Down Expand Up @@ -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
}
Expand Down
16 changes: 16 additions & 0 deletions test/files/neg/t3346i.check
Expand Up @@ -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
19 changes: 19 additions & 0 deletions test/files/neg/t4271.check
Expand Up @@ -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
16 changes: 16 additions & 0 deletions test/files/neg/t4457_1.check
Expand Up @@ -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
16 changes: 16 additions & 0 deletions test/files/neg/t4457_2.check
Expand Up @@ -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
4 changes: 4 additions & 0 deletions test/files/neg/t4568.check
@@ -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
4 changes: 4 additions & 0 deletions test/files/neg/t4889.check
@@ -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
4 changes: 4 additions & 0 deletions test/files/neg/t5728.check
@@ -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
7 changes: 7 additions & 0 deletions test/files/neg/t6436.check
Expand Up @@ -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
7 changes: 7 additions & 0 deletions test/files/neg/t6436b.check
Expand Up @@ -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
5 changes: 4 additions & 1 deletion test/files/neg/t6567.check
@@ -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)
^
Expand All @@ -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
4 changes: 4 additions & 0 deletions test/files/neg/t6667.check
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/files/neg/t6667.scala
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions test/files/neg/t692.check
Expand Up @@ -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
7 changes: 7 additions & 0 deletions test/files/neg/t712.check
@@ -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
7 changes: 7 additions & 0 deletions test/files/neg/t7131.check
Expand Up @@ -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

0 comments on commit ac5a670

Please sign in to comment.