Skip to content

Commit

Permalink
Merge pull request #95 from gnovark/topic/absType-crash
Browse files Browse the repository at this point in the history
Fix regression around await of non-class type
  • Loading branch information
retronym committed Dec 10, 2014
2 parents 38416ae + 13bc13d commit 4951474
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/main/scala/scala/async/internal/TransformUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,10 @@ private[async] trait TransformUtils {
(cls.info.decls.find(sym => sym.isMethod && sym.asTerm.isParamAccessor) getOrElse NoSymbol)

def mkZero(tp: Type): Tree = {
if (tp.typeSymbol.asClass.isDerivedValueClass) {
val argZero = mkZero(derivedValueClassUnbox(tp.typeSymbol).infoIn(tp).resultType)
val baseType = tp.baseType(tp.typeSymbol) // use base type here to dealias / strip phantom "tagged types" etc.
val tpSym = tp.typeSymbol
if (tpSym.isClass && tpSym.asClass.isDerivedValueClass) {
val argZero = mkZero(derivedValueClassUnbox(tpSym).infoIn(tp).resultType)
val baseType = tp.baseType(tpSym) // use base type here to dealias / strip phantom "tagged types" etc.

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

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

Expand Down
15 changes: 15 additions & 0 deletions src/test/scala/scala/async/run/toughtype/ToughType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,21 @@ class ToughTypeSpec {
val result = Await.result(fut, 5.seconds)
result mustBe None
}

@Test def awaitOfAbstractType(): Unit = {
import ExecutionContext.Implicits.global

def combine[A](a1: A, a2: A): A = a1

def combineAsync[A](a1: Future[A], a2: Future[A]) = async {
combine(await(a1), await(a2))
}

val fut = combineAsync(Future(1), Future(2))

val result = Await.result(fut, 5.seconds)
result mustEqual 1
}
}

class IntWrapper(val value: String) extends AnyVal {
Expand Down

0 comments on commit 4951474

Please sign in to comment.