Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SI-9248 Improve test #11

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/typechecker/Infer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ trait Infer extends Checkable {
)
}
if (settings.warnInferAny) {
foreachWithIndex(targs){ (targ, idx) =>
foreachWithIndex(targs) { (targ, idx) =>
val tparam = tparams(idx)
if (!tparam.isMonomorphicType && !targ.isHigherKinded)
reporter.warning(argumentPosition(idx), s"type inference relied on kind-polymorphic nature of inferred type `$targ` to conform to type parameter ${tparam.defString}")
Expand Down
4 changes: 3 additions & 1 deletion test/files/neg/t9248.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
warning: there were two feature warnings; re-run with -feature for details
t9248.scala:13: warning: type inference relied on kind-polymorphic nature of inferred type `Any` to conform to type parameter F[A]
def test3 = {
^
error: No warnings can be incurred under -Xfatal-warnings.
one warning found
one error found
2 changes: 1 addition & 1 deletion test/files/neg/t9248.flags
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-Xfatal-warnings
-Xfatal-warnings -language:_ -Xlint:infer-any
6 changes: 3 additions & 3 deletions test/files/neg/t9248.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ object Test {
def f[F[A], A](f: F[A]) = ???
def test1(u: Unary[Any]) = f(u)

// reports inference error, cannot unifiy Binary[Any, Any] with ?F[?A]
// reports inference error, cannot unify Binary[Any, Any] with ?F[?A]
// commented out as we can't have errors in a test for warnings.
// def test2(u: Binary[Any, Any]) = f(u)

def test3 = {
implicit def b2u[A, B](b: Binary[A, B]): List[Int] = ???
val b: Binary[Any, Any] = null
f(b) // inference fails initially, but then we try to coerse the arguments
f(b) // inference fails initially, but then we try to coerce the arguments
//
// Under -Ytyper-debug, we see:
//
Expand All @@ -29,7 +29,7 @@ object Test {
//
// This leads to inference of ?F=Any, ?A=Nothing (this is kind-correct because Any/Nothing are kind polymorphic)
//
// When we instantatiate the method type of `f` with this, the formal parameter type is now just Any[Nothing]
// When we instantiate the method type of `f` with this, the formal parameter type is now just Any[Nothing]
// which is just Any.
//
// The provided argument of type `Binary[A, B]` now unifies with this, no implicit coercion required.
Expand Down
7 changes: 5 additions & 2 deletions test/files/neg/warn-inferred-any.check
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ warn-inferred-any.scala:16: warning: a type was inferred to be `AnyVal`; this ma
warn-inferred-any.scala:17: warning: a type was inferred to be `AnyVal`; this may indicate a programming error.
{ 1l to 5l contains 5d }
^
warn-inferred-any.scala:25: warning: a type was inferred to be `Any`; this may indicate a programming error.
warn-inferred-any.scala:26: warning: a type was inferred to be `Any`; this may indicate a programming error.
def za = f(1, "one")
^
warn-inferred-any.scala:27: warning: a type was inferred to be `Any`; this may indicate a programming error.
def zx = f2(1, "one")
^
error: No warnings can be incurred under -Xfatal-warnings.
four warnings found
5 warnings found
one error found
2 changes: 2 additions & 0 deletions test/files/neg/warn-inferred-any.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ trait Ys[+A] {

trait Zs {
def f[A](a: A*) = 42
def f2[X, A](a: A*) = 42 // fixme warns on the 2nd arg
def g[A >: Any](a: A*) = 42 // don't warn

def za = f(1, "one")
def zx = f2(1, "one")
def zu = g(1, "one")
}