Version 1 (modified by Chuck, 14 years ago) |
---|
This program quickly overflows the stack due to the unconditional recursive calls between .foo and .bar:
class A def main .foo(List<of int>()) def foo(t as List<of int>) .bar(Set<of int>()) def bar(s as Set<of int>) .foo(List<of int>())
On Microsoft .NET, a StackOverflowException will be produced. However, on NovellMono, the program will simply crash with some systems reporting a SIGSEGV and others displaying no additional output of any type. This behavior of the NovellMono VirtualMachine is out of control of the Cobra project, however, the Cobra compiler can add additional code generation to track stackframes and then complain if they reach an upper limit. This is invoked with the DetailedStackTrace option like so:
$ cobra -dst stackoverflow.cobra Cobra detected stack overflow: Last 20 frames: 480. def A.foo at line 5 481. def A.bar at line 7 482. def A.foo at line 5 483. def A.bar at line 7 484. def A.foo at line 5 485. def A.bar at line 7 486. def A.foo at line 5 487. def A.bar at line 7 488. def A.foo at line 5 489. def A.bar at line 7 490. def A.foo at line 5 491. def A.bar at line 7 492. def A.foo at line 5 493. def A.bar at line 7 494. def A.foo at line 5 495. def A.bar at line 7 496. def A.foo at line 5 497. def A.bar at line 7 498. def A.foo at line 5 499. def A.bar at line 7 500. def A.foo at line 4 Fail fast: Stack Overflow Exiting with -1
See also: DetailedStackTrace