@@ -2087,100 +2087,160 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
2087
2087
2088
2088
type Constant = dotc.core.Constants .Constant
2089
2089
2090
- object Constant extends ConstantModule :
2090
+ object Constant extends ConstantModule
2091
2091
2092
- object Boolean extends BooleanModule :
2093
- def apply ( x : Boolean ) : Constant = dotc.core. Constants . Constant (x )
2094
- def unapply ( constant : Constant ) : Option [ Boolean ] =
2095
- if constant.tag == dotc.core. Constants . BooleanTag then Some (constant.booleanValue )
2096
- else None
2097
- end Boolean
2092
+ given ConstantMethods : ConstantMethods with
2093
+ extension ( self : Constant )
2094
+ def value : Any = self.value
2095
+ def show : String = Extractors .showConstant( using QuotesImpl . this )(self )
2096
+ end extension
2097
+ end ConstantMethods
2098
2098
2099
- object Byte extends ByteModule :
2100
- def apply (x : Byte ): Constant = dotc.core.Constants .Constant (x)
2101
- def unapply (constant : Constant ): Option [Byte ] =
2102
- if constant.tag == dotc.core.Constants .ByteTag then Some (constant.byteValue)
2103
- else None
2104
- end Byte
2099
+ type BooleanConstant = dotc.core.Constants .Constant
2105
2100
2106
- object Short extends ShortModule :
2107
- def apply (x : Short ): Constant = dotc.core.Constants .Constant (x)
2108
- def unapply (constant : Constant ): Option [Short ] =
2109
- if constant.tag == dotc.core.Constants .ShortTag then Some (constant.shortValue)
2110
- else None
2111
- end Short
2101
+ object BooleanConstantTypeTest extends TypeTest [Constant , BooleanConstant ]:
2102
+ def unapply (x : Constant ): Option [BooleanConstant & x.type ] =
2103
+ if x.tag == dotc.core.Constants .BooleanTag then Some (x.asInstanceOf [BooleanConstant & x.type ]) else None
2104
+ end BooleanConstantTypeTest
2112
2105
2113
- object Int extends IntModule :
2114
- def apply (x : Int ): Constant = dotc.core.Constants .Constant (x)
2115
- def unapply (constant : Constant ): Option [Int ] =
2116
- if constant.tag == dotc.core.Constants .IntTag then Some (constant.intValue)
2117
- else None
2118
- end Int
2106
+ object BooleanConstant extends BooleanConstantModule :
2107
+ def apply (x : Boolean ): BooleanConstant = dotc.core.Constants .Constant (x)
2108
+ def unapply (constant : BooleanConstant ): Some [Boolean ] = Some (constant.booleanValue)
2109
+ end BooleanConstant
2119
2110
2120
- object Long extends LongModule :
2121
- def apply (x : Long ): Constant = dotc.core.Constants .Constant (x)
2122
- def unapply (constant : Constant ): Option [Long ] =
2123
- if constant.tag == dotc.core.Constants .LongTag then Some (constant.longValue)
2124
- else None
2125
- end Long
2111
+ type ByteConstant = dotc.core.Constants .Constant
2126
2112
2127
- object Float extends FloatModule :
2128
- def apply (x : Float ): Constant = dotc.core.Constants .Constant (x)
2129
- def unapply (constant : Constant ): Option [Float ] =
2130
- if constant.tag == dotc.core.Constants .FloatTag then Some (constant.floatValue)
2131
- else None
2132
- end Float
2113
+ object ByteConstantTypeTest extends TypeTest [Constant , ByteConstant ]:
2114
+ def unapply (x : Constant ): Option [ByteConstant & x.type ] =
2115
+ if x.tag == dotc.core.Constants .ByteTag then Some (x.asInstanceOf [ByteConstant & x.type ]) else None
2116
+ end ByteConstantTypeTest
2133
2117
2134
- object Double extends DoubleModule :
2135
- def apply (x : Double ): Constant = dotc.core.Constants .Constant (x)
2136
- def unapply (constant : Constant ): Option [Double ] =
2137
- if constant.tag == dotc.core.Constants .DoubleTag then Some (constant.doubleValue)
2138
- else None
2139
- end Double
2118
+ object ByteConstant extends ByteConstantModule :
2119
+ def apply (x : Byte ): ByteConstant = dotc.core.Constants .Constant (x)
2120
+ def unapply (constant : ByteConstant ): Some [Byte ] = Some (constant.byteValue)
2121
+ end ByteConstant
2140
2122
2141
- object Char extends CharModule :
2142
- def apply (x : Char ): Constant = dotc.core.Constants .Constant (x)
2143
- def unapply (constant : Constant ): Option [Char ] =
2144
- if constant.tag == dotc.core.Constants .CharTag then Some (constant.charValue)
2145
- else None
2146
- end Char
2123
+ type ShortConstant = dotc.core.Constants .Constant
2147
2124
2148
- object String extends StringModule :
2149
- def apply (x : String ): Constant = dotc.core.Constants .Constant (x)
2150
- def unapply (constant : Constant ): Option [String ] =
2151
- if constant.tag == dotc.core.Constants .StringTag then Some (constant.stringValue)
2152
- else None
2153
- end String
2154
-
2155
- object Unit extends UnitModule :
2156
- def apply (): Constant = dotc.core.Constants .Constant (())
2157
- def unapply (constant : Constant ): Boolean =
2158
- constant.tag == dotc.core.Constants .UnitTag
2159
- end Unit
2160
-
2161
- object Null extends NullModule :
2162
- def apply (): Constant = dotc.core.Constants .Constant (null )
2163
- def unapply (constant : Constant ): Boolean =
2164
- constant.tag == dotc.core.Constants .NullTag
2165
- end Null
2166
-
2167
- object ClassOf extends ClassOfModule :
2168
- def apply (x : TypeRepr ): Constant =
2169
- // TODO check that the type is a valid class when creating this constant or let Ycheck do it?
2170
- dotc.core.Constants .Constant (x)
2171
- def unapply (constant : Constant ): Option [TypeRepr ] =
2172
- if constant.tag == dotc.core.Constants .ClazzTag then Some (constant.typeValue)
2173
- else None
2174
- end ClassOf
2125
+ object ShortConstantTypeTest extends TypeTest [Constant , ShortConstant ]:
2126
+ def unapply (x : Constant ): Option [ShortConstant & x.type ] =
2127
+ if x.tag == dotc.core.Constants .ShortTag then Some (x.asInstanceOf [ShortConstant & x.type ]) else None
2128
+ end ShortConstantTypeTest
2175
2129
2176
- end Constant
2130
+ object ShortConstant extends ShortConstantModule :
2131
+ def apply (x : Short ): ShortConstant = dotc.core.Constants .Constant (x)
2132
+ def unapply (constant : ShortConstant ): Some [Short ] = Some (constant.shortValue)
2133
+ end ShortConstant
2177
2134
2178
- given ConstantMethods : ConstantMethods with
2179
- extension (self : Constant )
2180
- def value : Any = self.value
2181
- def show : String = Extractors .showConstant(using QuotesImpl .this )(self)
2182
- end extension
2183
- end ConstantMethods
2135
+ type IntConstant = dotc.core.Constants .Constant
2136
+
2137
+ object IntConstantTypeTest extends TypeTest [Constant , IntConstant ]:
2138
+ def unapply (x : Constant ): Option [IntConstant & x.type ] =
2139
+ if x.tag == dotc.core.Constants .IntTag then Some (x.asInstanceOf [IntConstant & x.type ]) else None
2140
+ end IntConstantTypeTest
2141
+
2142
+ object IntConstant extends IntConstantModule :
2143
+ def apply (x : Int ): IntConstant = dotc.core.Constants .Constant (x)
2144
+ def unapply (constant : IntConstant ): Some [Int ] = Some (constant.intValue)
2145
+ end IntConstant
2146
+
2147
+ type LongConstant = dotc.core.Constants .Constant
2148
+
2149
+ object LongConstantTypeTest extends TypeTest [Constant , LongConstant ]:
2150
+ def unapply (x : Constant ): Option [LongConstant & x.type ] =
2151
+ if x.tag == dotc.core.Constants .LongTag then Some (x.asInstanceOf [LongConstant & x.type ]) else None
2152
+ end LongConstantTypeTest
2153
+
2154
+ object LongConstant extends LongConstantModule :
2155
+ def apply (x : Long ): LongConstant = dotc.core.Constants .Constant (x)
2156
+ def unapply (constant : LongConstant ): Some [Long ] = Some (constant.longValue)
2157
+ end LongConstant
2158
+
2159
+ type FloatConstant = dotc.core.Constants .Constant
2160
+
2161
+ object FloatConstantTypeTest extends TypeTest [Constant , FloatConstant ]:
2162
+ def unapply (x : Constant ): Option [FloatConstant & x.type ] =
2163
+ if x.tag == dotc.core.Constants .FloatTag then Some (x.asInstanceOf [FloatConstant & x.type ]) else None
2164
+ end FloatConstantTypeTest
2165
+
2166
+ object FloatConstant extends FloatConstantModule :
2167
+ def apply (x : Float ): FloatConstant = dotc.core.Constants .Constant (x)
2168
+ def unapply (constant : FloatConstant ): Some [Float ] = Some (constant.floatValue)
2169
+ end FloatConstant
2170
+
2171
+ type DoubleConstant = dotc.core.Constants .Constant
2172
+
2173
+ object DoubleConstantTypeTest extends TypeTest [Constant , DoubleConstant ]:
2174
+ def unapply (x : Constant ): Option [DoubleConstant & x.type ] =
2175
+ if x.tag == dotc.core.Constants .DoubleTag then Some (x.asInstanceOf [DoubleConstant & x.type ]) else None
2176
+ end DoubleConstantTypeTest
2177
+
2178
+ object DoubleConstant extends DoubleConstantModule :
2179
+ def apply (x : Double ): DoubleConstant = dotc.core.Constants .Constant (x)
2180
+ def unapply (constant : DoubleConstant ): Some [Double ] = Some (constant.doubleValue)
2181
+ end DoubleConstant
2182
+
2183
+ type CharConstant = dotc.core.Constants .Constant
2184
+
2185
+ object CharConstantTypeTest extends TypeTest [Constant , CharConstant ]:
2186
+ def unapply (x : Constant ): Option [CharConstant & x.type ] =
2187
+ if x.tag == dotc.core.Constants .CharTag then Some (x.asInstanceOf [CharConstant & x.type ]) else None
2188
+ end CharConstantTypeTest
2189
+
2190
+ object CharConstant extends CharConstantModule :
2191
+ def apply (x : Char ): CharConstant = dotc.core.Constants .Constant (x)
2192
+ def unapply (constant : CharConstant ): Some [Char ] = Some (constant.charValue)
2193
+ end CharConstant
2194
+
2195
+ type StringConstant = dotc.core.Constants .Constant
2196
+
2197
+ object StringConstantTypeTest extends TypeTest [Constant , StringConstant ]:
2198
+ def unapply (x : Constant ): Option [StringConstant & x.type ] =
2199
+ if x.tag == dotc.core.Constants .StringTag then Some (x.asInstanceOf [StringConstant & x.type ]) else None
2200
+ end StringConstantTypeTest
2201
+
2202
+ object StringConstant extends StringConstantModule :
2203
+ def apply (x : String ): StringConstant = dotc.core.Constants .Constant (x)
2204
+ def unapply (constant : StringConstant ): Some [String ] = Some (constant.stringValue)
2205
+ end StringConstant
2206
+
2207
+ type UnitConstant = dotc.core.Constants .Constant
2208
+
2209
+ object UnitConstantTypeTest extends TypeTest [Constant , UnitConstant ]:
2210
+ def unapply (x : Constant ): Option [UnitConstant & x.type ] =
2211
+ if x.tag == dotc.core.Constants .UnitTag then Some (x.asInstanceOf [UnitConstant & x.type ]) else None
2212
+ end UnitConstantTypeTest
2213
+
2214
+ object UnitConstant extends UnitConstantModule :
2215
+ def apply (): UnitConstant = dotc.core.Constants .Constant (())
2216
+ def unapply (constant : UnitConstant ): true = true
2217
+ end UnitConstant
2218
+
2219
+ type NullConstant = dotc.core.Constants .Constant
2220
+
2221
+ object NullConstantTypeTest extends TypeTest [Constant , NullConstant ]:
2222
+ def unapply (x : Constant ): Option [NullConstant & x.type ] =
2223
+ if x.tag == dotc.core.Constants .NullTag then Some (x.asInstanceOf [NullConstant & x.type ]) else None
2224
+ end NullConstantTypeTest
2225
+
2226
+ object NullConstant extends NullConstantModule :
2227
+ def apply (): NullConstant = dotc.core.Constants .Constant (null )
2228
+ def unapply (constant : NullConstant ): true = true
2229
+ end NullConstant
2230
+
2231
+ type ClassOfConstant = dotc.core.Constants .Constant
2232
+
2233
+ object ClassOfConstantTypeTest extends TypeTest [Constant , ClassOfConstant ]:
2234
+ def unapply (x : Constant ): Option [ClassOfConstant & x.type ] =
2235
+ if x.tag == dotc.core.Constants .ClazzTag then Some (x.asInstanceOf [ClassOfConstant & x.type ]) else None
2236
+ end ClassOfConstantTypeTest
2237
+
2238
+ object ClassOfConstant extends ClassOfConstantModule :
2239
+ def apply (x : TypeRepr ): ClassOfConstant =
2240
+ // TODO check that the type is a valid class when creating this constant or let Ycheck do it?
2241
+ dotc.core.Constants .Constant (x)
2242
+ def unapply (constant : ClassOfConstant ): Some [TypeRepr ] = Some (constant.typeValue)
2243
+ end ClassOfConstant
2184
2244
2185
2245
object Implicits extends ImplicitsModule :
2186
2246
def search (tpe : TypeRepr ): ImplicitSearchResult =
0 commit comments