Skip to content

Avoid crash by handling by-names under Typed #13354

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
Aug 23, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ abstract class TransformByNameApply extends MiniPhase { thisPhase: DenotTransfor
if (argType.isBottomType) argType = formal.widenExpr
def wrap(arg: Tree) =
ref(defn.cbnArg).appliedToType(argType).appliedTo(arg).withSpan(arg.span)
arg match {
def unTyped(t: Tree): Tree = t match { case Typed(expr, _) => unTyped(expr) case _ => t }
unTyped(arg) match {
case Apply(Select(qual, nme.apply), Nil)
if qual.tpe.derivesFrom(defn.Function0) && (isPureExpr(qual) || qual.symbol.isAllOf(Inline | Param)) =>
wrap(qual)
Expand Down
31 changes: 31 additions & 0 deletions tests/pos/i13349.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
sealed trait Stream[+A]{
import Stream.*;

def foldRight[B](z: => B)(f: (A, => B) => B): B =
this match {
case Cons(h,t) => f(h(), t().foldRight(z)(f))
case _ => z
}

def append[B >: A](other : => Stream[B]) : Stream[B] =
foldRight(other : Stream[B])((elem, stream) => cons(elem, stream))

}

case object Empty extends Stream[Nothing]
case class Cons[+A](h: () => A, t: () => Stream[A]) extends Stream[A]

object Stream {

def cons[A](hd: => A, tl: => Stream[A]): Stream[A] = {
lazy val head = hd
lazy val tail = tl
Cons(() => head, () => tail)
}

def empty[A]: Stream[A] = Empty

def apply[A](as: A*): Stream[A] =
if (as.isEmpty) empty else cons(as.head, apply(as.tail: _*))

}
3 changes: 3 additions & 0 deletions tests/pos/i13349min.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Foo:
def foo(x: => Foo) = bar(x: Foo)
def bar(x: => Foo) = x