Aladdin - Scala Bugtracking
[#126] project: compiler priority: low category: bug
submitter assigned to status date submitted
Erik Martin fixed 2003-09-10 17:10:06.0
subject Wrapping a value in an object makes a definition recursive
code
class O {
  val Bar:Any => Any = ((x:Any) => Bar(x));
  val Tuple1(foo:(Any => Any)) = Tuple1((x:Any) => foo(x));
}
what happened
~/scala/bin/scalac O.scala 
O.scala:3: recursive value foo$ needs type
  val Tuple1(foo:(Any => Any)) = Tuple1((x:Any) => foo(x));
      ^
one error found
what expected Why is it OK to define Bar as a recursive funtion, but not foo, just because foo is passed inside a tuple?
[back to overview]
Changes of this bug report
Martin  edited on  2003-09-10 17:38:28.0
Because the second definition is a pattern definition, which is taken to be equivalent to the following code:
val foo = Tuple1(((x: Any) => foo(x))).match({
    case Tuple1((foo) : (Any)=>Any) => foo
  })
Note that even if we added a type to foo, the definition would still be recurive, and therefore illegal. The error message is, admittedly, not very helpful here.
Burak  edited on  2003-09-23 18:26:29.0
change priority
Lex  edited on  2006-03-28 13:43:46.0
At the least the error message here is confusing. But, what should this code do?

If you do val x = exp, can exp refer to x? I would think no, that it cannot. In that case, this example is a pattern match and should compile fine.

If, in val x = exp, exp can refer to x, then I believe the error is that the reference is not underneath a lambda.

A third possibility is that exp cannot refer to x and furthermore any attempt to do so should signal an error. In that case, the error message should be cleaned up....

Martin  edited on  2006-05-28 15:05:40.0