Skip to content
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

Handle hoisted super arguments correctly in elimByName #14057

Merged
merged 1 commit into from
Dec 7, 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 @@ -88,7 +88,7 @@ class HoistSuperArgs extends MiniPhase with IdentityDenotTransformer { thisPhase
def newSuperArgMethod(argType: Type) = {
val (staticFlag, methOwner) =
if (cls.owner.is(Package)) (JavaStatic, cls) else (EmptyFlags, cls.owner)
val argTypeWrtConstr = argType.subst(origParams, allParamRefs(constr.info))
val argTypeWrtConstr = argType.widenTermRefExpr.subst(origParams, allParamRefs(constr.info))
// argType with references to paramRefs of the primary constructor instead of
// local parameter accessors
newSymbol(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import Types._
import Flags._
import Decorators._
import DenotTransformers._
import core.StdNames.nme
import StdNames.nme
import NameKinds.SuperArgName
import ast.Trees._
import reporting.trace

Expand Down Expand Up @@ -51,7 +52,8 @@ abstract class TransformByNameApply extends MiniPhase { thisPhase: DenotTransfor
if qual.tpe.derivesFrom(defn.Function0) && (isPureExpr(qual) || qual.symbol.isAllOf(Inline | Param)) =>
wrap(qual)
case _ =>
if (isByNameRef(arg) || arg.symbol == defn.cbnArg) arg
if isByNameRef(arg) || arg.symbol == defn.cbnArg || arg.symbol.name.is(SuperArgName)
then arg
else wrap(mkByNameClosure(arg, argType))
}
case _ =>
Expand Down
46 changes: 46 additions & 0 deletions tests/pos/i14010.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
abstract class LazyList[+T] {
def head: T
def tail: LazyList[T]
def isEmpty: Boolean
def push[E >: T](top: => E): LazyList[E] =
new Push[E](top, this)
//def map[R](f: T => R): LazyList[R]
def append[E >: T](that: => LazyList[E]): LazyList[E]
}

private class Push[+T](top: => T, stack: => LazyList[T]) extends LazyList[T] {
override def head: T =
top
override def tail: LazyList[T] =
stack
override def isEmpty: Boolean =
false
//override def map[R](f: T => R): LazyList[R] =
// new Push[R](f(top), stack.map(f)) {
// override def map[R2](f2: R => R2): LazyList[R2] =
// Push.this.map(f2 compose f)
// }
override def append[E >: T](that: => LazyList[E]): LazyList[E] =
new Push[E](top, stack.append(that)) {
override def append[E2 >: E](that2: => LazyList[E2]): LazyList[E2] =
Push.this.append(that.append(that2))
}
}

object LazyList {
val empty =
new LazyList[Nothing] {
override def head: Nothing =
throw new NoSuchElementException
override def tail: LazyList[Nothing] =
throw new UnsupportedOperationException
override def isEmpty: Boolean =
true
//override def map[R](f: _ => R): LazyList[R] =
// this
override def append[E](that: => LazyList[E]): LazyList[E] =
that
}
def apply[T](elements: T*): LazyList[T] =
elements.foldRight[LazyList[T]](empty)(new Push(_, _))
}
3 changes: 3 additions & 0 deletions tests/pos/i14010a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Foo(top: => Int) {
def foo: Any = new Foo(top) { }
}