File tree 2 files changed +35
-1
lines changed
main/scala/scala/async/internal
test/scala/scala/async/run/toughtype 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -333,10 +333,20 @@ private[async] trait TransformUtils {
333
333
def mkZero (tp : Type ): Tree = {
334
334
if (tp.typeSymbol.asClass.isDerivedValueClass) {
335
335
val argZero = mkZero(derivedValueClassUnbox(tp.typeSymbol).infoIn(tp).resultType)
336
+ val baseType = tp.baseType(tp.typeSymbol) // use base type here to dealias / strip phantom "tagged types" etc.
337
+
338
+ // By explicitly attributing the types and symbols here, we subvert privacy.
339
+ // Otherwise, ticket86PrivateValueClass would fail.
340
+
341
+ // Approximately:
342
+ // q"new ${valueClass}[$..targs](argZero)"
336
343
val target : Tree = gen.mkAttributedSelect(
337
344
c.typecheck(atMacroPos(
338
- New (TypeTree (tp.baseType(tp.typeSymbol))))), tp.typeSymbol.asClass.primaryConstructor)
345
+ New (TypeTree (baseType)))), tp.typeSymbol.asClass.primaryConstructor)
346
+
339
347
val zero = gen.mkMethodCall(target, argZero :: Nil )
348
+
349
+ // restore the original type which we might otherwise have weakened with `baseType` above
340
350
gen.mkCast(zero, tp)
341
351
} else {
342
352
gen.mkZero(tp)
Original file line number Diff line number Diff line change @@ -286,13 +286,37 @@ class ToughTypeSpec {
286
286
val result = Await .result(fut, 5 .seconds)
287
287
result mustBe None
288
288
}
289
+
290
+ @ Test def ticket86PrivateValueClass (): Unit = {
291
+ import ExecutionContext .Implicits .global
292
+
293
+ def doAThing (param : PrivateWrapper ) = Future (None )
294
+
295
+ val fut = async {
296
+ Option (PrivateWrapper .Instance ) match {
297
+ case Some (valueHolder) =>
298
+ await(doAThing(valueHolder))
299
+ case None =>
300
+ None
301
+ }
302
+ }
303
+
304
+ val result = Await .result(fut, 5 .seconds)
305
+ result mustBe None
306
+ }
289
307
}
290
308
291
309
class IntWrapper (val value : String ) extends AnyVal {
292
310
def plusStr = Future .successful(value + " !" )
293
311
}
294
312
class ParamWrapper [T ](val value : T ) extends AnyVal
295
313
314
+ class PrivateWrapper private (private val value : String ) extends AnyVal
315
+ object PrivateWrapper {
316
+ def Instance = new PrivateWrapper (" " )
317
+ }
318
+
319
+
296
320
trait A
297
321
298
322
trait B
You can’t perform that action at this time.
0 commit comments