Skip to content

Regression in benhutchison/scalaswingcontrib  #22062

Closed
@WojciechMazur

Description

@WojciechMazur

Based on OpenCB failure in benhutchison/scalaswingcontrib - build logs

Compiler version

Last good release: 3.6.4-RC1-bin-20241121-5d1d274-NIGHTLY
First bad release: 3.6.4-RC1-bin-20241122-64411b6-NIGHTLY
Bisect points to 26ecda5

Minimized code

//> using scala 3.nightly

class Label
class Component

trait RenderableCellsCompanion {
  type Renderer[-A] <: CellRenderer[A]
  type DefaultRenderer[-A] <: Label & Renderer[A]

  trait CellRendererCompanion {
    type CellInfo
    def labeled[A](): DefaultRenderer[A]
    protected trait LabelRenderer[-A] extends CellRenderer[A]:
      override abstract def componentFor(info: companion.CellInfo): Component = super.componentFor(info)
  }
  trait CellRenderer[-A]:
    val companion: CellRendererCompanion
    def componentFor(cellInfo: companion.CellInfo): Component
}
sealed trait TreeRenderers extends RenderableCellsCompanion { this: Tree.type =>
  trait Renderer[-A] extends CellRenderer[A]:
    final override val companion = Renderer

  object Renderer extends CellRendererCompanion:
    final override class CellInfo
    override def labeled[A]() = new DefaultRenderer[A] with LabelRenderer[A] {}

  class DefaultRenderer[-A] extends Label with Renderer[A]:
    override def componentFor(info: Renderer.CellInfo): Component = ???
}

class Tree extends Component
object Tree extends TreeRenderers

Output

[error] ./test.scala:26:33
[error] anonymous class TreeRenderers.this.DefaultRenderer[A] with 
[error]   TreeRenderers.Renderer.LabelRenderer[A] {...} cannot be defined due to a conflict between its parents when
[error] implementing a super-accessor for componentFor in trait LabelRenderer:
[error] 
[error] 1. One of its parent (LabelRenderer) contains a call super.componentFor in its body,
[error]    and when a super-call in a trait is written without an explicit parent
[error]    listed in brackets, it is implemented by a generated super-accessor in
[error]    the class that extends this trait based on the linearization order of
[error]    the class.
[error] 2. Because DefaultRenderer comes before LabelRenderer in the linearization
[error]    order of $anon, and because DefaultRenderer overrides componentFor,
[error]    the super-accessor in $anon is implemented as a call to
[error]    super[DefaultRenderer].componentFor.
[error] 3. However,
[error]    (info: TreeRenderers.this.Renderer.CellInfo): Component (the type of super[DefaultRenderer].componentFor in $anon)
[error]    is not a subtype of
[error]    (cellInfo: Nothing): Component (the type of componentFor in trait LabelRenderer).
[error]    Hence, the super-accessor that needs to be generated in $anon
[error]    is illegal.
[error] 
[error] Here are two possible ways to resolve this:
[error] 
[error] 1. Change the linearization order of $anon such that
[error]    LabelRenderer comes before DefaultRenderer.
[error] 2. Alternatively, replace super.componentFor in the body of trait LabelRenderer by a
[error]    super-call to a specific parent, e.g. super[CellRenderer].componentFor
[error]     override def labeled[A]() = new DefaultRenderer[A] with LabelRenderer[A] {}
[error]                         

Expectation

We should check if that's actual regression or a fix to false-negative error.

Metadata

Metadata

Assignees

Labels

itype:bugregressionThis worked in a previous version but doesn't anymore

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions