COMMUNITY

Why static analyzer remove code instead of warning


(Michael Solomon) #1

Why it’s remove the code on output instead of telling us that we have unreachable code and such.
There is good resources about haxe’s static analyzer?
Thx!


(Mark) #2

I think the idea is that you don’t have to worry about it. Also because of conditional compilation in some cases it might be unreachable but in other cases it doesn’t, so not sure how much worth the information is.


(Kevin Leung) #3

I would say you don’t want a whole bunch of warnings telling you some variables/functions in some libraries (including the std lib) are not being used. Because I am pretty sure you will be getting A LOT of them.


(Michael Solomon) #4

hm… yes but for example, in jslint you get warning only for your code…


(Juraj Kirchheim) #5

JSLint and Haxe are hardly the same. Haxe actually produces code, while a linter doesn’t. Meaning if you have unreachable JS code, then a linter can’t eliminate it and reporting it gives you the opportunity to improve your file size.

Mostly though, Haxe does a lot of transformations to your code, which can easily make some of it unreachable. Example:

class Dummy {
  static public inline function foo(bar:Bool) {
    trace("foo");
    if (!bar) return;
    trace("bar");
  }
}

class Main {
  static function main() {
    Dummy.foo(false);
  }
}

After inlining you have:

class Main {
  static function main() {
    trace("foo");
    if (true) return;
    trace("bar");
  }
}

The 2nd trace is clearly unreachable and the if (true) is also superfluous. Similarly, macro expansion can also yield code that contains unreachable parts.


(Jens Fischer) #6

With vshaxe, some unused code is grayed out by diagnostics info from the compiler:


(Mark) #7

Is there a way to get diagnostics commandline?