haxe
                                
                                 haxe copied to clipboard
                                
                                    haxe copied to clipboard
                            
                            
                            
                        invalid assignment through `untyped` causes assertion fail
class Test {
  static function main() {
    var foo = new Foo();
    untyped foo.bar = function() trace('bar');
    foo.bar();
  }
}
class Foo { 
  public function new() { } 
  public inline function bar() trace('foo'); 
}
Results in assertion fail at https://github.com/HaxeFoundation/haxe/blob/f2f4dc15144c8c76597c1ec9dac66a0b23b5dcc7/src/typing/typer.ml#L514-L515 Without untyped it properly gives error message. Should this assertion be changed into error or should it be handled sooner?
Silly question: why should it even fail at compile time? I think it should try to perform the assignment at runtime and thus behavior according to whatever the runtime semantics are.
What will happen if you do (cast foo).bar = function ...?
@back2dos because it's inlined, but I guess that doesn't meant it shouldn't be able to do that. But it would be even more obscure, as it would compile, but not work. Hmm. @nadako it compiles, but since it's inlined, it still traces out 'foo'.
IMO this is wontfix. There are probably many ways to cause assertion failures through untyped.
FWIW it would be nice to attach some sensible messages to our assertion failures :D
I agree, assertions which rich end user should be fixed or replaced with proper error messages.