File tree 4 files changed +45
-7
lines changed
compiler/src/dotty/tools/dotc
library/src/dotty/runtime 4 files changed +45
-7
lines changed Original file line number Diff line number Diff line change @@ -990,4 +990,10 @@ class Definitions {
990
990
/** If the symbol is of the class scala.Phantom.Any or scala.Phantom.Nothing */
991
991
def isPhantomTerminalClass (sym : Symbol ) = (sym eq Phantom_AnyClass ) || (sym eq Phantom_NothingClass )
992
992
993
+
994
+ lazy val ErasedPhantomType : TypeRef = ctx.requiredClassRef(" dotty.runtime.ErasedPhantom" )
995
+ def ErasedPhantomClass (implicit ctx : Context ) = ErasedPhantomType .symbol.asClass
996
+
997
+ def ErasedPhantom_UNIT (implicit ctx : Context ) = ErasedPhantomClass .linkedClass.requiredValue(" UNIT" )
998
+
993
999
}
Original file line number Diff line number Diff line change @@ -20,9 +20,9 @@ import dotty.tools.dotc.core.Types.Type
20
20
object PhantomErasure {
21
21
22
22
/** Returns the default erased type of a phantom type */
23
- def erasedPhantomType (implicit ctx : Context ): Type = defn.BoxedUnitType
23
+ def erasedPhantomType (implicit ctx : Context ): Type = defn.ErasedPhantomType
24
24
25
25
/** Returns the default erased tree for a call to Phantom.assume */
26
- def erasedAssume (implicit ctx : Context ): Tree = ref(defn.BoxedUnit_UNIT )
26
+ def erasedAssume (implicit ctx : Context ): Tree = ref(defn.ErasedPhantom_UNIT )
27
27
28
28
}
Original file line number Diff line number Diff line change @@ -99,17 +99,19 @@ import Decorators._
99
99
val NoFieldNeeded = Lazy | Deferred | JavaDefined | (if (ctx.settings.YnoInline .value) EmptyFlags else Inline )
100
100
101
101
def isErasableBottomField (cls : Symbol ): Boolean = {
102
- // TODO: For Scala.js, return false if this field is in a js.Object unless it was a Phantom before erasure .
103
- // Could time travel to detect phantom types or add an annotation before erasure.
104
- ! field.isVolatile && ((cls eq defn.NothingClass ) || (cls eq defn.NullClass ) || (cls eq defn.BoxedUnitClass ))
102
+ // TODO: For Scala.js, return false if this field is in a js.Object unless it is an ErasedPhantomClass .
103
+ ! field.isVolatile &&
104
+ ((cls eq defn.NothingClass ) || (cls eq defn.NullClass ) || (cls eq defn.BoxedUnitClass ) || (cls eq defn. ErasedPhantomClass ))
105
105
}
106
106
107
107
def erasedBottomTree (sym : Symbol ) = {
108
108
if (sym eq defn.NothingClass ) Throw (Literal (Constant (null )))
109
109
else if (sym eq defn.NullClass ) Literal (Constant (null ))
110
+ else if (sym eq defn.BoxedUnitClass ) ref(defn.BoxedUnit_UNIT )
111
+ else if (sym eq defn.ErasedPhantomClass ) ref(defn.ErasedPhantom_UNIT )
110
112
else {
111
- assert(sym eq defn. BoxedUnitClass )
112
- ref(defn. BoxedUnit_UNIT )
113
+ assert(false ) // Not in sync with isErasableBottomField
114
+ EmptyTree
113
115
}
114
116
}
115
117
Original file line number Diff line number Diff line change
1
+ package dotty .runtime ;
2
+
3
+
4
+ /** Unit type representing an erased phantom value.
5
+ *
6
+ * Based on implementation of BoxedUnit.
7
+ */
8
+ public final class ErasedPhantom implements java .io .Serializable {
9
+ private static final long serialVersionUID = 4116021023472525845L ;
10
+
11
+ public final static ErasedPhantom UNIT = new ErasedPhantom ();
12
+
13
+ public final static Class <Void > TYPE = java .lang .Void .TYPE ;
14
+
15
+ private Object readResolve () { return UNIT ; }
16
+
17
+ private ErasedPhantom () { }
18
+
19
+ public boolean equals (java .lang .Object other ) {
20
+ return this == other ;
21
+ }
22
+
23
+ public int hashCode () {
24
+ return 0 ;
25
+ }
26
+
27
+ public String toString () {
28
+ return "(\uD83D \uDC7B )" ;
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments