Skip to content

Fix regression around type skolems and if exprs. #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/main/scala/scala/async/internal/AsyncTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,12 @@ trait AsyncTransform {
case ValDef(_, _, _, rhs) if liftedSyms(tree.symbol) =>
atOwner(currentOwner) {
val fieldSym = tree.symbol
val set = Assign(gen.mkAttributedStableRef(fieldSym.owner.thisType, fieldSym), transform(rhs))
changeOwner(set, tree.symbol, currentOwner)
localTyper.typedPos(tree.pos)(set)
val lhs = atPos(tree.pos) {
gen.mkAttributedStableRef(fieldSym.owner.thisType, fieldSym)
}
val assign = treeCopy.Assign(tree, lhs, transform(rhs)).setType(definitions.UnitTpe)
changeOwner(assign, tree.symbol, currentOwner)
assign
}
case _: DefTree if liftedSyms(tree.symbol) =>
EmptyTree
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/scala/async/internal/TransformUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private[async] trait TransformUtils {
case ld: LabelDef => ld.symbol
}.toSet
t.exists {
case rt: RefTree => !(labelDefs contains rt.symbol)
case rt: RefTree => rt.symbol != null && rt.symbol.isLabel && !(labelDefs contains rt.symbol)
case _ => false
}
}
Expand Down
63 changes: 63 additions & 0 deletions src/test/scala/scala/async/run/ifelse4/IfElse4.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2012-2014 Typesafe Inc. <http://www.typesafe.com>
*/

package scala.async
package run
package ifelse4

import language.{reflectiveCalls, postfixOps}
import scala.concurrent.{Future, ExecutionContext, future, Await}
import scala.concurrent.duration._
import scala.async.Async.{async, await}
import org.junit.Test


class TestIfElse4Class {

import ExecutionContext.Implicits.global

class F[A]
class S[A](val id: String)
trait P

case class K(f: F[_])

def result[A](f: F[A]) = async {
new S[A with P]("foo")
}

def run(k: K) = async {
val res = await(result(k.f))
// these triggered a crash with mismatched existential skolems
// found : S#10272[_$1#10308 with String#137] where type _$1#10308
// required: S#10272[_$1#10311 with String#137] forSome { type _$1#10311 }

// This variation of the crash could be avoided by fixing the over-eager
// generation of states in `If` nodes, which was caused by a bug in label
// detection code.
if(true) {
identity(res)
}

// This variation remained after the aforementioned fix, however.
// It was fixed by manually typing the `Assign(liftedField, rhs)` AST,
// which is how we avoid these problems through the rest of the ANF transform.
if(true) {
identity(res)
await(result(k.f))
}
res
}
}

class IfElse4Spec {

@Test
def `await result with complex type containing skolem`() {
val o = new TestIfElse4Class
val fut = o.run(new o.K(null))
val res = Await.result(fut, 2 seconds)
res.id mustBe ("foo")
}
}