| [#1080] | project: compiler | priority: low | category: bug | |
|---|---|---|---|---|
| submitter | assigned to | status | date submitted | |
| Nikolay | Iulian | fixed | 2007-05-01 13:12:20.0 | |
| subject | [contrib #436] unexpected failure to identify tail recursion | |||
| code |
object A
{
val name = "1/2/3"
val l_brief = new StringBuilder(name.length)
def loop(a_index : Int) : Unit =
{
Console.println("loop depth: " + (new Exception).getStackTrace.length)
l_brief.append(name.charAt(a_index))
val l_slash = name.indexOf("/", a_index)
Console.println("a_index: " + a_index + ", l_slash: " + l_slash)
if (-1 != l_slash)
{
loop(1 + l_slash)
}
}
loop(0)
val briefName =
l_brief.toString
Console.println(briefName)
}
object B
{
val name = "1/2/3"
val briefName =
{
val l_brief = new StringBuilder(name.length)
def loop(a_index : Int) : Unit =
{
Console.println("loop depth: " + (new Exception).getStackTrace.length)
l_brief.append(name.charAt(a_index))
val l_slash = name.indexOf("/", a_index)
Console.println("a_index: " + a_index + ", l_slash: " + l_slash)
if (-1 != l_slash)
{
loop(1 + l_slash)
}
}
loop(0)
l_brief.toString
}
Console.println(briefName)
}
object Main extends Application
{
Console.println("Output of A:")
val a = A
Console.println()
Console.println("Output of B:")
val b = B
}
|
|||
| what happened | With the above code in Test.scala: $rm -rf classes && mkdir classes && scalac Test.scala -d classes && (cd classes ; scala Main) Output of A: loop depth: 13 a_index: 0, l_slash: 1 loop depth: 13 a_index: 2, l_slash: 3 loop depth: 13 a_index: 4, l_slash: -1 123 Output of B: loop depth: 13 a_index: 0, l_slash: 1 loop depth: 14 a_index: 2, l_slash: 3 loop depth: 15 a_index: 4, l_slash: -1 123 |
|||
| what expected | The depths under Output of B to all be 13. | |||
| [back to overview] | ||||
| Nikolay edited on 2007-05-01 13:13:04.0 |
| contribution #436 |
| Iulian edited on 2007-05-01 17:04:20.0 |