scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
231 stars 21 forks source link

overriding checks should normalise type aliases #144

Open scabug opened 16 years ago

scabug commented 16 years ago

when reporting a problem with overriding an abstract type with a concrete type, the involved type should be normalised so the error message becomes more explicit

trait Lists { // developed by Func Inc.
  type TList[x] <: List[x]
  trait List[T]
}

// Our component
trait MyComponent { self: Lists with MyComponent =>
  val input: TList[Int]
}

trait SpecialLists extends Lists {
  // The following does not type check:
  type TList[x <: B] <: BoundedList[x]

  trait B
  trait BoundedList[T <: B] extends List[T]   
}

error message:

error: error overriding type TList in trait Lists with bounds [x]>: Nothing <: SpecialLists.this.List[x];
 type TList has incompatible type SpecialLists.this.TList[x]
  type TList[x <: B] <: BoundedList[x]
       ^
scabug commented 16 years ago

Imported From: https://issues.scala-lang.org/browse/SI-144?orig=1 Reporter: @adriaanm

joroKr21 commented 5 years ago

Currently (on Scala 2.13.0) the error message is:

On line 13: error: incompatible type in overriding
       type TList[x] <: SpecialLists.this.List[x] (defined in trait Lists);
        found   : [x(in type TList) <: SpecialLists.this.B] <: SpecialLists.this.BoundedList[x(in type TList)]
        required: [x(in type TList)] <: SpecialLists.this.List[x(in type TList)]

I don't know if it's clear enough or not

eed3si9n commented 4 years ago

Here's Dotty (0.20.0-RC1):

[error] -- Error: /private/tmp/si-144/src/main/scala/Lists.scala:13:7 ------------------
[error] 13 |  type TList[x <: B] <: BoundedList[x]
[error]    |       ^
[error]    |error overriding type TList in trait Lists with bounds <: SpecialLists.this.List;
[error]    |  type TList with bounds <: SpecialLists.this.BoundedList has incompatible type
[error] one error found
[error] (Compile / compileIncremental) Compilation failed