Skip to content

@:using not working as intended when handling Class<> and Enum<> #10106

@ZwodahS

Description

@ZwodahS

Considering the following code

class EnExtension {
    public static function toS(e: En): String {
        return '${e}';
    }
    public static function fromS(en: Enum<En>, st: String): En {
        return A;
    }
}
@:using(Test.EnExtension)
enum En {
    A;
    B;
}
class Test {
  static public function main() {
      var e: En = A;
      trace(e.toS());
      var f: En = En.fromS("A"); // Error ?
  }
}

The similar thing also happen with Class<>

class CExtension {
    public static function toS(c: C): String {
        return 'c';
    }
    public static function fromS(cls: Class<C>, s: String) {
        return new C();
    }
}

@:using(Test.CExtension)
class C {
    public function new(){}
}


class Test {
  static public function main() {
      var c = new C();
      trace(c.toS());
      var d = C.fromS('c'); // Error ?
      trace(d);
  }
}

This don't seems to be a problem with static extensions but rather a problem with @:using. By explicitly defining using Test.CExtensions and using Test.EnExtensions, the code will run just fine.

Couldn't find an existing issues regarding this, if there is one, kindly just close the issue.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions