Skip to content

Improve error messages reporting overriding errors that involve refinements #22997

Open
@kyouko-taiga

Description

@kyouko-taiga

Compiler version

Scala compiler version 3.6.4 -- Copyright 2002-2025, LAMP/EPFL

Minimized example

trait Collection[Self]:
  me =>
  type Position
  type Element
  extension (self: Self)
    def apply(p: Position): Element

  trait Sliceable:
    type Slice
    given sliceIsCollection: (Collection[Slice] { type Position = me.Position; type Element = me.Element })
    extension (self: Self)
      def withSlice(low: Position, high: Position): Slice

  val sliceable: (Sliceable { type Slice = DefaultSlice[Self, Position] }) = new Sliceable:
    type Slice = DefaultSlice[Self, Position]
    given sliceIsCollection: (Collection[Slice] { type Position = me.Position; type Element = me.Element }) =
      defaultSliceIsCollection[Self, Position, Element](using me)
    extension (self: Self)
      def withSlice(low: Position, high: Position): DefaultSlice[Self, Position] =
        DefaultSlice(self, low, high)
  export sliceable.withSlice

case class DefaultSlice[B, P](base: B, low: P, high: P)

given defaultSliceIsCollection[B, P, E](using
    b: Collection[B] { type Position = P; type Element = E }
): Collection[DefaultSlice[B, P]] with
  type Position = P
  type Element = E
  extension (self: DefaultSlice[B, P])
    def apply(p: P): E = b.apply(self.base)(p)
  override val sliceable: (Sliceable { type Slice = DefaultSlice[B, Position] }) = new Sliceable:
    type Slice = DefaultSlice[B, Position]
    given sliceIsCollection: (Collection[Slice] { type Position = P; type Element = E }) =
      defaultSliceIsCollection[B, Position, Element](using b)
    extension (self: DefaultSlice[B, P])
      def withSlice(low: Position, high: Position): DefaultSlice[B, Position] =
        DefaultSlice(self.base, low, high)

given Collection[String] with
  type Position = Int
  type Element = Char
  extension (self: String)
    def apply(p: Int): Char = self.charAt(p)

Output Error/Warning message

[error] error overriding value sliceable in trait Collection of type defaultSliceIsCollection.this.Sliceable{
[error]   type Slice =
[error]     DefaultSlice[DefaultSlice[B, P], defaultSliceIsCollection.this.Position]
[error] };
[error]   value sliceable of type defaultSliceIsCollection.this.Sliceable{
[error]   type Slice = DefaultSlice[B, defaultSliceIsCollection.this.Position]} has incompatible type
[error]   override val sliceable: (Sliceable { type Slice = DefaultSlice[B, Position] }) = new Sliceable:
[error]   

Why this Error/Warning was not helpful

The error message is not ideal because it is difficult to parse what's different between the two types.

Suggested improvement

It would help if we had a sort of diff between the types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:overloadingarea:reportingError reporting including formatting, implicit suggestions, etcbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesitype:enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions