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

infinite stream within extends argument causes exception #2487

Closed
scabug opened this issue Oct 19, 2009 · 7 comments
Closed

infinite stream within extends argument causes exception #2487

scabug opened this issue Oct 19, 2009 · 7 comments
Assignees

Comments

@scabug
Copy link

scabug commented Oct 19, 2009

The following code causes an exception when compiling. The problem exists in 2.8.0.r19132 and 2.7.6.final. The example works if intsFrom is defined elsewhere. The exception trace is attached.

class C1(l: List[Int])

class C2 extends C1({
def intsFrom(n: Int): Stream[Int] = Stream.cons(n, intsFrom(n+1))
intsFrom(0).take(10).toList
})

@scabug
Copy link
Author

scabug commented Oct 19, 2009

Imported From: https://issues.scala-lang.org/browse/SI-2487?orig=1
Reporter: Avi Pfeffer (apfeffer)
Attachments:

  • issue.txt (created on Oct 19, 2009 1:17:06 PM UTC, 24593 bytes)

@scabug
Copy link
Author

scabug commented Oct 19, 2009

@paulp said:
Ah, the old define a recursive method in a block as part of a superconstructor argument trick. Similar in some ways to #1909, in that it taxes the lifting abilities a bit too far.

@scabug
Copy link
Author

scabug commented Nov 8, 2009

@odersky said:
Here's a simpler example which makes this fail:

class A(x: Int)

object B {
  def bar(n: => Int) = n
}

class B extends A ({
  def foo(n: => Int): Int = if (n == 0) 1 else B.bar(foo(n - 1))
  foo(10)
})

The problem is the recursive call to class foo in the anonymous class that's created
for bar's call by name parameter. To resolve that call lambda lift tries to find member foo' of B. But since foo' is defined in the constructor, it is not a member of `B'.

@scabug
Copy link
Author

scabug commented Nov 8, 2009

@paulp said:
Replying to [comment:6 odersky]:

The problem is the recursive call to class foo in the anonymous class that's created
for bar's call by name parameter. To resolve that call lambda lift tries to find member foo' of B. But since foo' is defined in the constructor, it is not a member of `B'.

To my naive eye it looks like always lifting functions defined inside constructor or super calls into the companion object rather than the instance would solve this issue. As I understand it, that was the solution to #1909. If methods defined in these places can't reference "this" anyway since it doesn't exist yet, what is lost by making it static?

@scabug
Copy link
Author

scabug commented Nov 14, 2012

@paulp said:
Closing as a duplicate of #6666 because it has a cooler number.

@scabug
Copy link
Author

scabug commented Nov 15, 2012

@SethTisue said:
the ticket is still open?

@scabug
Copy link
Author

scabug commented Nov 15, 2012

@paulp said:
Right, I was just telling you something I'd do someday. Oh look, today is the day. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants