bug
bug copied to clipboard
Tail recursion behaviour is unspecified
The word "tail" appears only twice in the SLS, both as method names in example 5.3.3. So it appears that the current (rather delicate!) behaviour of tail recursion is in fact a completely unspecified feature. It would be nice if this could be fixed. :-)
Imported From: https://issues.scala-lang.org/browse/SI-1219?orig=1 Reporter: @DRMacIver
@paulp said: A note for when/if this is specified, as of r17315 there is a @tailrec annotation.
Does this still hold true for the current versions?
@nogurenn if you have a look yourself and find out one way or the other, let us know
The word "tail" appears only twice in the SLS
$ rg "\btail" .
02-identifiers-names-and-scopes.md
114:object X { type T = annotation.tailrec }
115:object Y { type T = annotation.tailrec }
117: import X._, Y._, annotation.{tailrec => T} // OK, all T mean tailrec
118: @T def f: Int = { f ; 42 } // error, f is not tail recursive
07-implicits.md
107: else m.add(xs.head, sum(xs.tail))
05-classes-and-objects.md
833: var tail: LinkedList[A] = null
835: def this(head: A, tail: LinkedList[A]) = { this(head); this.tail = tail }
841:third one constructs a list with a given head and tail.
The word "tail" appears 7 times, one of which as "tail recursive", and tailrec appears 4 times, used as a weird example of import renaming. The tail recursion in general continues to be unspecified.
The weird example is tweaked in https://github.com/scala/scala/pull/10162/files (Tweaked not for weirdness but correctness: rename on import is higher precedence than wildcard, undermining the point of the example.)
I will supply doc in the annotations section for tailrec and switch. (I also went looking for it.)