Skip to content

Commit 4951474

Browse files
committed
Merge pull request #95 from gnovark/topic/absType-crash
Fix regression around await of non-class type
2 parents 38416ae + 13bc13d commit 4951474

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/main/scala/scala/async/internal/TransformUtils.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,10 @@ private[async] trait TransformUtils {
331331
(cls.info.decls.find(sym => sym.isMethod && sym.asTerm.isParamAccessor) getOrElse NoSymbol)
332332

333333
def mkZero(tp: Type): Tree = {
334-
if (tp.typeSymbol.asClass.isDerivedValueClass) {
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.
334+
val tpSym = tp.typeSymbol
335+
if (tpSym.isClass && tpSym.asClass.isDerivedValueClass) {
336+
val argZero = mkZero(derivedValueClassUnbox(tpSym).infoIn(tp).resultType)
337+
val baseType = tp.baseType(tpSym) // use base type here to dealias / strip phantom "tagged types" etc.
337338

338339
// By explicitly attributing the types and symbols here, we subvert privacy.
339340
// Otherwise, ticket86PrivateValueClass would fail.
@@ -342,7 +343,7 @@ private[async] trait TransformUtils {
342343
// q"new ${valueClass}[$..targs](argZero)"
343344
val target: Tree = gen.mkAttributedSelect(
344345
c.typecheck(atMacroPos(
345-
New(TypeTree(baseType)))), tp.typeSymbol.asClass.primaryConstructor)
346+
New(TypeTree(baseType)))), tpSym.asClass.primaryConstructor)
346347

347348
val zero = gen.mkMethodCall(target, argZero :: Nil)
348349

src/test/scala/scala/async/run/toughtype/ToughType.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,21 @@ class ToughTypeSpec {
304304
val result = Await.result(fut, 5.seconds)
305305
result mustBe None
306306
}
307+
308+
@Test def awaitOfAbstractType(): Unit = {
309+
import ExecutionContext.Implicits.global
310+
311+
def combine[A](a1: A, a2: A): A = a1
312+
313+
def combineAsync[A](a1: Future[A], a2: Future[A]) = async {
314+
combine(await(a1), await(a2))
315+
}
316+
317+
val fut = combineAsync(Future(1), Future(2))
318+
319+
val result = Await.result(fut, 5.seconds)
320+
result mustEqual 1
321+
}
307322
}
308323

309324
class IntWrapper(val value: String) extends AnyVal {

0 commit comments

Comments
 (0)