aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/transform/ValueClasses.scala
diff options
context:
space:
mode:
authorGuillaume Martres <smarter@ubuntu.com>2015-03-18 23:56:07 +0100
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2015-05-01 13:26:22 +0200
commit391c80c4dfb2489e4098af33265b22332ef3d5f1 (patch)
tree206abc627f2a4cf5404547f554cd448492351a16 /src/dotty/tools/dotc/transform/ValueClasses.scala
parentf168970f38df1d1ccc2b262f1a77f72cd4ec9f39 (diff)
downloaddotty-391c80c4dfb2489e4098af33265b22332ef3d5f1.tar.gz
dotty-391c80c4dfb2489e4098af33265b22332ef3d5f1.tar.bz2
dotty-391c80c4dfb2489e4098af33265b22332ef3d5f1.zip
Add synthetic casts to and from ErasedValueType
For a value class V, let U be the underlying type after erasure. We add to the companion object of V two cast methods: def u2evt$(x0: U): ErasedValueType(V, U) def evt2u$(x0: ErasedValueType(V, U)): U The casts are used in Erasure to make it typecheck, they are then removed in ElimErasedValueType (not yet present in this commit). This is different from the implementation of value classes in Scala 2 (see SIP-15) which uses `asInstanceOf` which does not typecheck.
Diffstat (limited to 'src/dotty/tools/dotc/transform/ValueClasses.scala')
-rw-r--r--src/dotty/tools/dotc/transform/ValueClasses.scala14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/transform/ValueClasses.scala b/src/dotty/tools/dotc/transform/ValueClasses.scala
index 9cd0e1ef7..8969b9321 100644
--- a/src/dotty/tools/dotc/transform/ValueClasses.scala
+++ b/src/dotty/tools/dotc/transform/ValueClasses.scala
@@ -35,6 +35,20 @@ object ValueClasses {
.map(_.symbol)
.getOrElse(NoSymbol)
+ /** For a value class `d`, this returns the synthetic cast from the underlying type to
+ * ErasedValueType defined in the companion module. This method is added to the module
+ * and further described in [[ExtensionMethods]].
+ */
+ def u2evt(d: ClassDenotation)(implicit ctx: Context): Symbol =
+ d.linkedClass.info.decl(nme.U2EVT).symbol
+
+ /** For a value class `d`, this returns the synthetic cast from ErasedValueType to the
+ * underlying type defined in the companion module. This method is added to the module
+ * and further described in [[ExtensionMethods]].
+ */
+ def evt2u(d: ClassDenotation)(implicit ctx: Context): Symbol =
+ d.linkedClass.info.decl(nme.EVT2U).symbol
+
/** The unboxed type that underlies a derived value class */
def underlyingOfValueClass(d: ClassDenotation)(implicit ctx: Context): Type =
valueClassUnbox(d).info.resultType