Back to Scala3

E138: Trait Parameter Used As Parent Prefix

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

3.8.4953 B
Original Source

E138: Trait Parameter Used As Parent Prefix

This error occurs when a trait tries to extend a parent type that is derived from the trait's own parameters.

Using a trait parameter as the prefix for a parent type is disallowed to prevent outer-related NullPointerException errors at runtime. The parent class initialization happens before trait parameters are available, which would cause runtime failures.

Note: This error code is typically caught by an earlier compiler phase with a different error message. The TraitParameterUsedAsParentPrefix check in RefChecks serves as a safety net but is rarely triggered in practice because PostTyper catches the same scenarios first.

<!-- 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>