Skip to content

Commit

Permalink
Streams: don't blow up on unknown "asTraversable" param in flatten (i…
Browse files Browse the repository at this point in the history
…ssue #22)
  • Loading branch information
ochafik committed Mar 22, 2015
1 parent 96c7bdf commit 1021f8e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ Core/.cache

.history
CasbahDSL.original
react-0.12.2
39 changes: 18 additions & 21 deletions Streams/src/main/scala/streams/ops/FlattenOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,26 @@ private[streams] trait FlattenOps

object SomeFlattenOp extends StreamOpExtractor {
private[this] lazy val PredefSymbol = rootMirror.staticModule("scala.Predef")
override def unapply(tree: Tree) = Option(tree) collect {
case q"$target.flatten[$tpt]($asTraversable)" if {
asTraversable match {
case q"$predef.`$conforms`[$colTpt]" if predef.symbol == PredefSymbol =>
// println(s"colTpt = $colTpt, target.tpe = ${target.tpe}")
target.tpe match {
case TypeRef(_, _, List(internalColTpe)) =>
internalColTpe =:= colTpt.tpe
case _ =>
false
}

case Strip(Function(List(param), Option2Iterable(ref))) if param.symbol == ref.symbol =>
true

private[this] def isAKnownAsTraversable(asTrav: Tree, targetTpe: Type) = asTrav match {
case q"$predef.`$conforms`[$colTpt]" if predef.symbol == PredefSymbol =>
targetTpe match {
case TypeRef(_, _, List(internalColTpe)) =>
internalColTpe =:= colTpt.tpe
case _ =>
false
}
} =>

case Strip(Function(List(param), Option2Iterable(ref))) if param.symbol == ref.symbol =>
true

case _ =>
false
}

override def unapply(tree: Tree) = Option(tree) collect {
case q"$target.flatten[$tpt]($asTrav)" if isAKnownAsTraversable(asTrav, target.tpe) =>
(target, FlattenOp(tpt.tpe))
// case _ if {
// println("NOT A FLATTEN: " + tree)
// false
// } =>
// ???
}
}

Expand Down Expand Up @@ -75,7 +73,6 @@ private[streams] trait FlattenOps
nextOps)

sub.copy(body = List(withQuietWarnings(transform(typed(q"""
// TODO: plug that lambda's symbol as the new owner of sub.body's decls.
${vars.alias.get}.foreach(($itemValDef) => {
..${sub.body};
})
Expand Down

0 comments on commit 1021f8e

Please sign in to comment.