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

type was inferred to be AnyVal/Any; this may indicate a programming error. #12662

Closed
He-Pin opened this issue Oct 9, 2022 · 3 comments
Closed

Comments

@He-Pin
Copy link
Contributor

He-Pin commented Oct 9, 2022

Reproduction steps

Scala version: 2.3.10

ByteString.empty.indexOf(5) should ===(-1)

Problem

[10-09 04:53:38.583] [error] /home/runner/work/akka/akka/akka-actor-tests/src/test/scala/akka/util/ByteStringSpec.scala:634:24: a type was inferred to be `AnyVal`; this may indicate a programming error.
[10-09 04:53:38.583] [error]       ByteString.empty.indexOf(5) should ===(-1)

and

[10-09 04:53:37.041] [error] /home/runner/work/akka/akka/akka-actor-tests/src/test/scala/akka/util/ByteIteratorSpec.scala:24:23: a type was inferred to be `AnyVal`; this may indicate a programming error.
[10-09 04:53:37.042] [error]       freshIterator().indexOf(0x10, 3) should be(5)
[10-09 04:53:28.219] [error] /home/runner/work/akka/akka/akka-actor-tests/src/test/scala/akka/actor/FSMActorSpec.scala:256:19: a type was inferred to be `Any`; this may indicate a programming error.
[10-09 04:53:28.219] [error]         .parseMap(Map("akka.loglevel" -> "DEBUG", "akka.actor.debug.fsm" -> true).asJava)
[10-09 04:53:28.220] [error]                   ^
[10-09 04:53:30.674] [error] /home/runner/work/akka/akka/akka-actor-tests/src/test/scala/akka/actor/dispatch/ActorModelSpec.scala:235:32: a type was inferred to be `Object`; this may indicate a programming error.
[10-09 04:53:30.675] [error]             Option(dispatcher).getOrElse(this).getClass,

from : https://github.com/akka/akka/actions/runs/3212916837/jobs/5252192044

akka/akka#31648

  1. the indexOf method returns Int , so should not get an error.
    image
    image

Explain how the above behavior isn't what you expected.

compiles correctly.

@som-snytt
Copy link

som-snytt commented Oct 9, 2022

-Vprint:typer says

      ByteIteratorSpec.this.convertToAnyShouldWrapper[Int](freshIterator().indexOf[AnyVal](32))((Position.apply("ByteIteratorSpec.scala", "Please set the environment variable SCALACTIC_FILL_FILE_PATHNAMES to yes at compile time to enable this feature.", 19): org.scalactic.source.Position), scalactic.this.Prettifier.default).should(ByteIteratorSpec.this.be.apply(0));

for

[error] .../akka/akka-actor-tests/src/test/scala/akka/util/ByteIteratorSpec.scala:19:23: a type was inferred to be `AnyVal`; this may indicate a programming error.
[error]       freshIterator().indexOf(0x20) should be(0)

where

  def indexOf(elem: Byte): Int = indexOf(elem, 0)
  def indexOf(elem: Byte, from: Int): Int = indexWhere(_ == elem, from)

  override def indexOf[B >: Byte](elem: B): Int = indexOf(elem, 0)
  override def indexOf[B >: Byte](elem: B, from: Int): Int = indexWhere(_ == elem, from)

Probably indexOf(0x20: Byte). Otherwise the arg is an Int. This is why we need byte literals.

Edit: or, of course, explicit type arg.

@som-snytt
Copy link

I see that the ticket under which the behavior was tweaked explicitly mentions ScalaTest in this regard.

#12441

@som-snytt
Copy link

Looked at another example in ActorModelSpec, which is also a classic.

Option(dispatcher).getOrElse(this).getClass

is

scala.Option.apply[akka.dispatch.MessageDispatcher](dispatcher).getOrElse[Object](this).getClass()

but could be expressed

Option(dispatcher).map(_.getClass).getOrElse(getClass)

but I guess after you see it, you might prefer the explicit getOrElse[Object].

scala.Option.apply[akka.dispatch.MessageDispatcher](dispatcher).map[Class[_ <: akka.dispatch.MessageDispatcher]](((x$1: akka.dispatch.MessageDispatcher) => x$1.getClass())).getOrElse[Class[_1] forSome { type T <: akka.dispatch.MessageDispatcher; type _1 >: T with T <: Object }](ActorModelSpec.this.getClass())

It would be nice not to warn if a universal method is invoked on the inferred type somewhere.

@som-snytt som-snytt closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants