HaxeFoundation / haxe

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

[macro] Impossible to differentiate method-statics and regular vars #11682

Closed Yanrishatum closed 4 weeks ago

Yanrishatum commented 4 weeks ago

Method-static variables have no distinct characteristics from regular variables on a macro level after typing.

class Test {
  static function main() {
    var local = "hello";
    static var methodLocal = "world";
  }
}

Both are typed as TLocal, as well as both are listed in Context.getLocalTVars() without any clear indication that methodLocal is a static var.

Expected: Typed as TField, pointing at the generated class-level static var, or at least some indication in the TVar that variable is a method-static variable.

Affected versions: Haxe stable and nightly. Full reproduction code using hl.Ref to cause a compile time error on static var: https://try.haxe.org/#A17c580D