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

An unnecessary reflective call is generated when the method can be accessed from self-type #11448

Open
Atry opened this Issue Mar 25, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@Atry
Copy link

commented Mar 25, 2019

abstract class Foo {
  def i: Int
} 
object Foo {
  trait Bar { this: Foo => } 

  def main(args: Array[String]): Unit = {
    val bar: Bar { def i: Int } = new Foo with Bar { def i = 1 } 
    bar.i
  }
}
scalac -feature Foo.scala 
Foo.scala:11: warning: reflective access of structural type member method i should be enabled
by making the implicit value scala.language.reflectiveCalls visible.
This can be achieved by adding the import clause 'import scala.language.reflectiveCalls'
or by setting the compiler option -language:reflectiveCalls.
See the Scaladoc for value scala.language.reflectiveCalls for a discussion
why the feature should be explicitly enabled.
    bar.i
        ^
one warning found

I expect bar.i is not a reflective call, because the backend should be able to use the information of self-type to perform a invokevirtual call.

@Atry Atry changed the title Unnecessary reflective calls are generated when the method can be accessed from self-type An unnecessary reflective call is generated when the method can be accessed from self-type Mar 25, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.