haxe icon indicating copy to clipboard operation
haxe copied to clipboard

invalid assignment through `untyped` causes assertion fail

Open Antriel opened this issue 6 years ago • 6 comments

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?

Antriel avatar Apr 30 '19 10:04 Antriel

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.

back2dos avatar Apr 30 '19 10:04 back2dos

What will happen if you do (cast foo).bar = function ...?

nadako avatar Apr 30 '19 10:04 nadako

@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'.

Antriel avatar Apr 30 '19 10:04 Antriel

IMO this is wontfix. There are probably many ways to cause assertion failures through untyped.

Simn avatar Apr 30 '19 11:04 Simn

FWIW it would be nice to attach some sensible messages to our assertion failures :D

nadako avatar Apr 30 '19 11:04 nadako

I agree, assertions which rich end user should be fixed or replaced with proper error messages.

RealyUniqueName avatar May 18 '19 19:05 RealyUniqueName