HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.03k stars 648 forks source link

fix cast error if Std.string fails #11607

Open ncannasse opened 3 months ago

ncannasse commented 3 months ago

This fixes an error when a toString() raises an error, this can be reproduced with the following sample:

class Foo {
   var o : Map<String, Foo> = [];
   public function new() {
      o.set("x", this);
   }
   public function toString() {
        return "Foo:"+o; // will stack overflow
   }
}
class Main {
    static function main() {
        cast(new Foo(), Main); // should raise cast error
    }
}

Should be tested and fixed on other platforms as well.