Skip to content

Commit f4275e2

Browse files
committed
Fix compiler crash with value class in result position
We were leaking untyped trees out of the macro, which crashed in refchecks. This commit proactively typechecks the tree returned by `mkZero`.
1 parent 1568a28 commit f4275e2

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,8 @@ private[async] trait TransformUtils {
343343
New(TypeTree(baseType)))), tpSym.asClass.primaryConstructor)
344344

345345
val zero = gen.mkMethodCall(target, argZero :: Nil)
346-
347346
// restore the original type which we might otherwise have weakened with `baseType` above
348-
gen.mkCast(zero, tp)
347+
c.typecheck(atMacroPos(gen.mkCast(zero, tp)))
349348
} else {
350349
gen.mkZero(tp)
351350
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,19 @@ class ToughTypeSpec {
319319
val result = Await.result(fut, 5.seconds)
320320
result mustEqual 1
321321
}
322+
323+
// https://github.com/scala/async/issues/106
324+
@Test def valueClassT106(): Unit = {
325+
import scala.async.internal.AsyncId._
326+
async {
327+
"whatever value" match {
328+
case _ =>
329+
await("whatever return type")
330+
new IntWrapper("value class matters")
331+
}
332+
"whatever return type"
333+
}
334+
}
322335
}
323336

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

0 commit comments

Comments
 (0)