File tree Expand file tree Collapse file tree 3 files changed +36
-1
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 3 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,8 @@ abstract class TransformByNameApply extends MiniPhase { thisPhase: DenotTransfor
45
45
if (argType.isBottomType) argType = formal.widenExpr
46
46
def wrap (arg : Tree ) =
47
47
ref(defn.cbnArg).appliedToType(argType).appliedTo(arg).withSpan(arg.span)
48
- arg match {
48
+ def unTyped (t : Tree ): Tree = t match { case Typed (expr, _) => unTyped(expr) case _ => t }
49
+ unTyped(arg) match {
49
50
case Apply (Select (qual, nme.apply), Nil )
50
51
if qual.tpe.derivesFrom(defn.Function0 ) && (isPureExpr(qual) || qual.symbol.isAllOf(Inline | Param )) =>
51
52
wrap(qual)
Original file line number Diff line number Diff line change
1
+ sealed trait Stream [+ A ]{
2
+ import Stream .* ;
3
+
4
+ def foldRight [B ](z : => B )(f : (A , => B ) => B ): B =
5
+ this match {
6
+ case Cons (h,t) => f(h(), t().foldRight(z)(f))
7
+ case _ => z
8
+ }
9
+
10
+ def append [B >: A ](other : => Stream [B ]) : Stream [B ] =
11
+ foldRight(other : Stream [B ])((elem, stream) => cons(elem, stream))
12
+
13
+ }
14
+
15
+ case object Empty extends Stream [Nothing ]
16
+ case class Cons [+ A ](h : () => A , t : () => Stream [A ]) extends Stream [A ]
17
+
18
+ object Stream {
19
+
20
+ def cons [A ](hd : => A , tl : => Stream [A ]): Stream [A ] = {
21
+ lazy val head = hd
22
+ lazy val tail = tl
23
+ Cons (() => head, () => tail)
24
+ }
25
+
26
+ def empty [A ]: Stream [A ] = Empty
27
+
28
+ def apply [A ](as : A * ): Stream [A ] =
29
+ if (as.isEmpty) empty else cons(as.head, apply(as.tail: _* ))
30
+
31
+ }
Original file line number Diff line number Diff line change
1
+ class Foo :
2
+ def foo (x : => Foo ) = bar(x : Foo )
3
+ def bar (x : => Foo ) = x
You can’t perform that action at this time.
0 commit comments