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

Fix semantics of inline override #8533

Closed
nicolasstucki opened this issue Mar 12, 2020 · 1 comment
Closed

Fix semantics of inline override #8533

nicolasstucki opened this issue Mar 12, 2020 · 1 comment

Comments

@nicolasstucki
Copy link
Contributor

The current semantics of inline override is inconsistent and confusing.

Current state

class Greeting {
  def greet(name: String): String = "Greetings " + name
}

class Hello extends Greeting {
  inline override def greet(name: String): String = "Hello " + name
}

object App {
  val greeting: Greeting = new Greeting
  val hello1: Hello = new Hello
  val hello2: Greeting = hello1


  println(greeting.greet("World")) // prints: Greetings World

  println(hello1.greet("World")) // prints: Hello World
  // Inlined Hello.greet directly

  println(hello2.greet("World")) // prints: Greetings World
  // Not inlined as it is statically calling Greeting.greet, so far so good
  // It should have dynamically call Hello.greet, but inline method are erased!
}

Semantically coherent version

object App {
  val greeting: Greeting = new Greeting
  val hello1: Hello = new Hello
  val hello2: Greeting = hello1

  println(greeting.greet("World")) // prints: Greetings World

  println(hello1.greet("World")) // prints: Hello World
  // Inlined as we call Hello.greet directly

  println(hello2.greet("World")) // prints: Hello World
  // Not inlined as it is statiacally calling Greeting.greet.
  // Dynamically calls Hello.greet
}

How to make this happen

class Hello extends Greeting {
  inline override def greet(name: String): String = "Hello " + name
}

should become

class Hello extends Greeting {
  override def greet(name: String): String = "Hello " + name
}

and

class Hello extends Greeting {
  inline override def greet(name: String): String = ${ myHello('name) }
}

would become

class Hello extends Greeting {
  override def greet(name: String): String = ${ myHello('name) } // where macro is evaluated in place
}
@bishabosha
Copy link
Member

this appears fixed by #8543

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