haxe-overload icon indicating copy to clipboard operation
haxe-overload copied to clipboard

Context.typeof has side effects (inference. others?)

Open jcward opened this issue 6 years ago • 1 comments

As shown here: http://try-haxe.mrcdk.com/#DeCd8

Calling Context.typeof can cause monomorphs to harden. So my strategy of "call typeof until one succeeds" is not 100% fail-safe.

I could warn if any of the incoming params are monomorphs (though I think the behavior could be deeper than the params themselves?)

jcward avatar Jul 12 '18 17:07 jcward

Idea: replace monomorph inputs (just for the typeof call) with throw-away variables... So instead of typing:

tools_class.replace(subject, [foo, bar]);

Upon detecting that foo is a monomorph, instead type:

{
  var __protect_foo;
  tools_class.replace(subject, [__protect_foo, b]) ;
}

Thus, foo is not morphed and __protect_foo is just a temporary identifier.

jcward avatar Jul 12 '18 18:07 jcward