Back to Scala3

E082: Super Calls Not Allowed In Inlineable

docs/_docs/reference/error-codes/E082.md

3.8.41.9 KB
Original Source

E082: Super Calls Not Allowed In Inlineable

This error is emitted when an inline method contains a call to super.

Method inlining prohibits calling superclass methods because when the method is inlined at the call site, the super reference would be ambiguous or invalid - it would no longer refer to the superclass of the defining class.


Example

scala
class Parent:
  def greet: String = "Hello"

class Child extends Parent:
  inline def greetLoud: String = super.greet + "!"

Error

scala
-- [E082] Syntax Error: example.scala:5:33 -------------------------------------
5 |  inline def greetLoud: String = super.greet + "!"
  |                                 ^^^^^
  |                     Super call not allowed in inlineable method greetLoud
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | Method inlining prohibits calling superclass methods, as it may lead to confusion about which super is being called.
   -----------------------------------------------------------------------------

Solution

scala
// Remove the inline modifier
class Parent:
  def greet: String = "Hello"

class Child extends Parent:
  def greetLoud: String = super.greet + "!"
scala
// Or use a helper method for the super call
class Parent:
  def greet: String = "Hello"

class Child extends Parent:
  private def parentGreet: String = super.greet
  inline def greetLoud: String = parentGreet + "!"
<!-- SOURCE-ONLY: Remove the notice below once this page has been manually updated. --> <aside class="warning"> This reference page was created with LLM assistance - the description of the error code may not be accurate or cover all possible scenarios. </aside>