Skip to content

Overriding a method with a inline method is inconstant #4892

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

Closed
nicolasstucki opened this issue Aug 4, 2018 · 3 comments
Closed

Overriding a method with a inline method is inconstant #4892

nicolasstucki opened this issue Aug 4, 2018 · 3 comments

Comments

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Aug 4, 2018

class Foo extends Bar {
  inline override def bar: Int = 2
}

class Bar {
  def bar: Int = 1
}

object Test {
  def main(args: Array[String]): Unit = {
    val a: Foo = new Foo
    val b: Bar = new Foo
    println(a.bar) // prints 2
    println(b.bar) // prints 1 but should print 2
  }
}
@Blaisorblade
Copy link
Contributor

This isn't a "bug", only questionable semantics, since currently transparent methods aren't meant to be dispatches at runtime. And without runtime dispatch, we have no choice here:

def baz(b: Bar) = println(b.bar)
baz(new Foo) // must give 1

So here I'll abuse "stat:needs spec" for "we must pick our poison".

@nicolasstucki
Copy link
Contributor Author

Then I would consider it buggy semantics. I would argue that either we have runtime semantics or we disallow overrides. #4860 gives the correct runtime semantics.

@nicolasstucki nicolasstucki changed the title Overriding a method with a transparent method is inconstant Overriding a method with a inline method is inconstant Oct 24, 2018
@nicolasstucki
Copy link
Contributor Author

As discussed these are the semantics we want.

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

3 participants