bug icon indicating copy to clipboard operation
bug copied to clipboard

Unable to convert inner.F to Inner#F if Inner is an abstract type

Open scabug opened this issue 9 years ago • 3 comments

Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_102).
Type in expressions for evaluation. Or try :help.

scala> :paste
// Entering paste mode (ctrl-D to finish)

trait Converter {
  type To
  type From
}
object Converter {
  type Aux[-From0, +To0] = Converter {
    type To <: To0
    type From >: From0
  }
}
trait Outer {
  trait InnerLike { this: Inner =>
    type To
    type From
    type F = Converter.Aux[From, To]
  }
  type Inner <: InnerLike
  def cast(inner: Inner)(f: inner.F): Inner#F = f
}

// Exiting paste mode, now interpreting.

<console>:28: error: type mismatch;
 found   : inner.F
    (which expands to)  Converter{type To <: inner.To; type From >: inner.From}
 required: Converter{type To <: _2.To; type From >: _2.From} forSome { val _2: Outer.this.Inner }
         def cast(inner: Inner)(f: inner.F): Inner#F = f
                                                       ^

scabug avatar Oct 26 '16 01:10 scabug

Imported From: https://issues.scala-lang.org/browse/SI-10008?orig=1 Reporter: @Atry Affected Versions: 2.10.6, 2.11.8, 2.12.0

scabug avatar Oct 26 '16 01:10 scabug

@Atry said (edited on Nov 1, 2016 2:22:39 PM UTC):

trait Converter {
  type To
  type From
}
object Converter {
  type Aux[-From0, +To0] = Converter {
    type To <: To0
    type From >: From0
  }
}
trait Outer {
  trait InnerLike { this: Inner =>
    type To
    type From
    type F >: Converter.Aux[From, To] <: Converter.Aux[From, To] // This works
  }
  type Inner <: InnerLike
  def cast(inner: Inner)(f: inner.F): Inner#F = f
}

A workaround is making F an abstract type.

scabug avatar Nov 01 '16 07:11 scabug

"fixed in Scala 3" in the sense that Inner#F is now illegal since Inner is abstract

SethTisue avatar Apr 06 '25 18:04 SethTisue