Skip to content

Improve error messages reporting overriding errors that involve refinements #22997

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

Open
kyouko-taiga opened this issue Apr 14, 2025 · 0 comments
Labels
area:overloading area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement

Comments

@kyouko-taiga
Copy link
Contributor

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.

@kyouko-taiga kyouko-taiga added area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 14, 2025
@Gedochao Gedochao added area:overloading and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:overloading area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement
Projects
None yet
Development

No branches or pull requests

2 participants