Skip to content

Fix more corner cases in late expansion #179

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 2 commits into from
Nov 20, 2017
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
2 changes: 1 addition & 1 deletion src/main/scala/scala/async/internal/AnfTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private[async] trait AnfTransform {
case MatchEnd(ld) =>
deriveLabelDef(ld, branchWithAssign)
case blk @ Block(thenStats, thenExpr) =>
treeCopy.Block(blk, thenStats, typedAssign(thenExpr)).setType(definitions.UnitTpe)
treeCopy.Block(blk, thenStats, branchWithAssign(thenExpr)).setType(definitions.UnitTpe)
case _ =>
typedAssign(t)
}
Expand Down
40 changes: 40 additions & 0 deletions src/main/scala/scala/async/internal/TransformUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,51 @@ private[async] trait TransformUtils {
treeCopy.If(tree, cond1, thenp1, elsep1)
case Apply(fun, args) if isLabel(fun.symbol) =>
internal.setType(treeCopy.Apply(tree, api.recur(fun), args map api.recur), UnitTpe)
case vd @ ValDef(mods, name, tpt, rhs) if isCaseTempVal(vd.symbol) =>
def addUncheckedBounds(t: Tree) = {
typingTransform(t, owner) {
(tree, api) =>
internal.setType(api.default(tree), uncheckedBoundsIfNeeded(tree.tpe))
}

}
val uncheckedRhs = addUncheckedBounds(api.recur(rhs))
val uncheckedTpt = addUncheckedBounds(tpt)
internal.setInfo(vd.symbol, uncheckedBoundsIfNeeded(vd.symbol.info))
treeCopy.ValDef(vd, mods, name, uncheckedTpt, uncheckedRhs)
case t => api.default(t)
}
}
}

private def isExistentialSkolem(s: Symbol) = {
val EXISTENTIAL: Long = 1L << 35
internal.isSkolem(s) && (internal.flags(s).asInstanceOf[Long] & EXISTENTIAL) != 0
}
private def isCaseTempVal(s: Symbol) = {
s.isTerm && s.asTerm.isVal && s.isSynthetic && s.name.toString.startsWith("x")
}

def uncheckedBoundsIfNeeded(t: Type): Type = {
var quantified: List[Symbol] = Nil
var badSkolemRefs: List[Symbol] = Nil
t.foreach {
case et: ExistentialType =>
quantified :::= et.quantified
case TypeRef(pre, sym, args) =>
val illScopedSkolems = args.map(_.typeSymbol).filter(arg => isExistentialSkolem(arg) && !quantified.contains(arg))
badSkolemRefs :::= illScopedSkolems
case _ =>
}
if (badSkolemRefs.isEmpty) t
else t.map {
case tp @ TypeRef(pre, sym, args) if args.exists(a => badSkolemRefs.contains(a.typeSymbol)) =>
uncheckedBounds(tp)
case t => t
}
}


final def mkMutableField(tpt: Type, name: TermName, init: Tree): List[Tree] = {
if (isPastTyper) {
// If we are running after the typer phase (ie being called from a compiler plugin)
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/scala/async/run/late/LateExpansion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ abstract class LatePlugin extends Plugin {
}
}

override val runsAfter: List[String] = "refchecks" :: Nil
override val runsAfter: List[String] = "patmat" :: Nil
override val phaseName: String = "postpatmat"

})
Expand Down