Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ object OpaqueTypeSpec {
}

// Illustrate how to dyanmically decide between OpaqueType or not
sealed trait MaybeBoxed[T <: Data] extends Record {
sealed abstract class MaybeBoxed[T <: Data] extends Record {
Comment thread
jackkoenig marked this conversation as resolved.
def underlying: T
def boxed: Boolean
}
Expand All @@ -115,12 +115,12 @@ object OpaqueTypeSpec {
class Boxed[T <: Data](gen: T) extends MaybeBoxed[T] {
def boxed = true
lazy val elements = SeqMap("underlying" -> gen)
def underlying = elements.head._2
def underlying = elements.head._2.asInstanceOf[T]
}
Comment on lines 117 to 119
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this code doesn't matter that much, users often look at the tests for examples and this is not the right way to fix this.

What is happening, is that in Scala 2.13, the type of lazy val elements infers to be SeqMap[String, T] (the more specific type), while Scala 3 keeps the type as SeqMap[String, Data]. More to the spirit of the original test would be to add that type annotation and thus remove the need for the cast.

Better yet than that though would be to change this to just:

val underlying = gen
lazy val elements = SeqMap("underlying" -> underlying)

class Unboxed[T <: Data](gen: T) extends MaybeBoxed[T] with OpaqueType {
def boxed = false
lazy val elements = SeqMap("" -> gen)
def underlying = elements.head._2
def underlying = elements.head._2.asInstanceOf[T]
}

class MaybeNoAsUInt(noAsUInt: Boolean) extends Record with OpaqueType {
Expand Down
Loading