-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15625 from dotty-staging/fix-15618
Fix two problems related to match types as array elements
- Loading branch information
Showing
7 changed files
with
105 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-- Error: tests/neg/i15618.scala:17:44 --------------------------------------------------------------------------------- | ||
17 | def toArray: Array[ScalaType[T]] = Array() // error | ||
| ^ | ||
| No ClassTag available for ScalaType[T] | ||
| | ||
| where: T is a type in class Tensor with bounds <: DType | ||
| | ||
| | ||
| Note: a match type could not be fully reduced: | ||
| | ||
| trying to reduce ScalaType[T] | ||
| failed since selector T | ||
| does not match case Float16 => Float | ||
| and cannot be shown to be disjoint from it either. | ||
| Therefore, reduction cannot advance to the remaining cases | ||
| | ||
| case Float32 => Float | ||
| case Int32 => Int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
sealed abstract class DType | ||
sealed class Float16 extends DType | ||
sealed class Float32 extends DType | ||
sealed class Int32 extends DType | ||
|
||
object Float16 extends Float16 | ||
object Float32 extends Float32 | ||
object Int32 extends Int32 | ||
|
||
type ScalaType[U <: DType] <: Int | Float = U match | ||
case Float16 => Float | ||
case Float32 => Float | ||
case Int32 => Int | ||
|
||
class Tensor[T <: DType](dtype: T): | ||
def toSeq: Seq[ScalaType[T]] = Seq() | ||
def toArray: Array[ScalaType[T]] = Array() // error | ||
|
||
@main | ||
def Test = | ||
val t = Tensor(Float32) // Tensor[Float32] | ||
println(t.toSeq.headOption) // works, Seq[Float] | ||
println(t.toArray.headOption) // ClassCastException |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Some(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
sealed abstract class DType | ||
sealed class Float16 extends DType | ||
sealed class Float32 extends DType | ||
sealed class Int32 extends DType | ||
|
||
object Float16 extends Float16 | ||
object Float32 extends Float32 | ||
object Int32 extends Int32 | ||
|
||
type ScalaType[U <: DType] <: Int | Float = U match | ||
case Float16 => Float | ||
case Float32 => Float | ||
case Int32 => Int | ||
|
||
abstract class Tensor[T <: DType]: | ||
def toArray: Array[ScalaType[T]] | ||
|
||
object IntTensor extends Tensor[Int32]: | ||
def toArray: Array[Int] = Array(1, 2, 3) | ||
|
||
@main | ||
def Test = | ||
val t = IntTensor: Tensor[Int32] | ||
println(t.toArray.headOption) // was ClassCastException |