Skip to content

Commit 80ec523

Browse files
authored
Merge pull request #14057 from dotty-staging/fix-14010
Handle hoisted super arguments correctly in elimByName
2 parents 097356d + 0114f79 commit 80ec523

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

compiler/src/dotty/tools/dotc/transform/HoistSuperArgs.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class HoistSuperArgs extends MiniPhase with IdentityDenotTransformer { thisPhase
8888
def newSuperArgMethod(argType: Type) = {
8989
val (staticFlag, methOwner) =
9090
if (cls.owner.is(Package)) (JavaStatic, cls) else (EmptyFlags, cls.owner)
91-
val argTypeWrtConstr = argType.subst(origParams, allParamRefs(constr.info))
91+
val argTypeWrtConstr = argType.widenTermRefExpr.subst(origParams, allParamRefs(constr.info))
9292
// argType with references to paramRefs of the primary constructor instead of
9393
// local parameter accessors
9494
newSymbol(

compiler/src/dotty/tools/dotc/transform/TransformByNameApply.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import Types._
1111
import Flags._
1212
import Decorators._
1313
import DenotTransformers._
14-
import core.StdNames.nme
14+
import StdNames.nme
15+
import NameKinds.SuperArgName
1516
import ast.Trees._
1617
import reporting.trace
1718

@@ -51,7 +52,8 @@ abstract class TransformByNameApply extends MiniPhase { thisPhase: DenotTransfor
5152
if qual.tpe.derivesFrom(defn.Function0) && (isPureExpr(qual) || qual.symbol.isAllOf(Inline | Param)) =>
5253
wrap(qual)
5354
case _ =>
54-
if (isByNameRef(arg) || arg.symbol == defn.cbnArg) arg
55+
if isByNameRef(arg) || arg.symbol == defn.cbnArg || arg.symbol.name.is(SuperArgName)
56+
then arg
5557
else wrap(mkByNameClosure(arg, argType))
5658
}
5759
case _ =>

tests/pos/i14010.scala

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
abstract class LazyList[+T] {
2+
def head: T
3+
def tail: LazyList[T]
4+
def isEmpty: Boolean
5+
def push[E >: T](top: => E): LazyList[E] =
6+
new Push[E](top, this)
7+
//def map[R](f: T => R): LazyList[R]
8+
def append[E >: T](that: => LazyList[E]): LazyList[E]
9+
}
10+
11+
private class Push[+T](top: => T, stack: => LazyList[T]) extends LazyList[T] {
12+
override def head: T =
13+
top
14+
override def tail: LazyList[T] =
15+
stack
16+
override def isEmpty: Boolean =
17+
false
18+
//override def map[R](f: T => R): LazyList[R] =
19+
// new Push[R](f(top), stack.map(f)) {
20+
// override def map[R2](f2: R => R2): LazyList[R2] =
21+
// Push.this.map(f2 compose f)
22+
// }
23+
override def append[E >: T](that: => LazyList[E]): LazyList[E] =
24+
new Push[E](top, stack.append(that)) {
25+
override def append[E2 >: E](that2: => LazyList[E2]): LazyList[E2] =
26+
Push.this.append(that.append(that2))
27+
}
28+
}
29+
30+
object LazyList {
31+
val empty =
32+
new LazyList[Nothing] {
33+
override def head: Nothing =
34+
throw new NoSuchElementException
35+
override def tail: LazyList[Nothing] =
36+
throw new UnsupportedOperationException
37+
override def isEmpty: Boolean =
38+
true
39+
//override def map[R](f: _ => R): LazyList[R] =
40+
// this
41+
override def append[E](that: => LazyList[E]): LazyList[E] =
42+
that
43+
}
44+
def apply[T](elements: T*): LazyList[T] =
45+
elements.foldRight[LazyList[T]](empty)(new Push(_, _))
46+
}

tests/pos/i14010a.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Foo(top: => Int) {
2+
def foo: Any = new Foo(top) { }
3+
}

0 commit comments

Comments
 (0)