Skip to content

Commit f3d675d

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`. (cherry picked from commit f4275e2)
1 parent 9da0183 commit f3d675d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ private[async] trait TransformUtils {
262262
typer.typedPos(macroPos)(
263263
New(TypeTree(tp.baseType(tp.typeSymbol)))), tp.typeSymbol.primaryConstructor)
264264
val zero = gen.mkMethodCall(target, argZero :: Nil)
265-
gen.mkCast(zero, tp)
265+
// restore the original type which we might otherwise have weakened with `baseType` above
266+
typer.typedPos(macroPos)(gen.mkCast(zero, tp))
266267
} else {
267268
gen.mkZero(tp)
268269
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,19 @@ class ToughTypeSpec {
286286
val result = Await.result(fut, 5.seconds)
287287
result mustBe None
288288
}
289+
290+
// https://github.com/scala/async/issues/106
291+
@Test def valueClassT106(): Unit = {
292+
import scala.async.internal.AsyncId._
293+
async {
294+
"whatever value" match {
295+
case _ =>
296+
await("whatever return type")
297+
new IntWrapper("value class matters")
298+
}
299+
"whatever return type"
300+
}
301+
}
289302
}
290303

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

0 commit comments

Comments
 (0)