Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"@:using" is not working on interfaces. #8022

Closed
posxposy opened this issue Mar 20, 2019 · 10 comments
Closed

"@:using" is not working on interfaces. #8022

posxposy opened this issue Mar 20, 2019 · 10 comments

Comments

@posxposy
Copy link

Hello! :)

//using Test.TestTools; //Works
class Test implements ITest {
  static function main() {
        new Test().test();
  }
  
  function new(){}
}

@:using(Test.TestTools) //Not works
interface ITest {}

class TestTools {
    public static inline function test(v:ITest):Void {
        trace("Test!");
    }
}

Error: Test.hx:3: characters 9-24 : Test has no field test
http://try-haxe.mrcdk.com/#7Cd23

Haxe 4. RC1

@Gama11
Copy link
Member

Gama11 commented Mar 20, 2019

At this point I'm wondering, what does @:using work on? :D

@Simn
Copy link
Member

Simn commented Mar 20, 2019

This shouldn't work. @:using on a type only has an effect when a field access is made on that type. The compiler doesn't explore all related types to find all possible static extensions.

We will document this accordingly.

@nadako
Copy link
Member

nadako commented Mar 20, 2019

I don't know, this looks like a somewhat legit use-case and it looks like it should work. And we don't have to explore anything here, right? We can inherit @:using when processing class heritage.

@Simn
Copy link
Member

Simn commented Mar 20, 2019

We can, but I don't think we should because this gets very magical.

I'm inclined to go the opposite way and restrict @:using to enums. That's why I originally added it, and because enums don't have sub-types we don't have to worry about complexity.

@nadako
Copy link
Member

nadako commented Mar 20, 2019

restrict @:using to enums

Well, I can live with that. If we error on other types it'll at least look as something actually designed and not randomly (not) working :-) And we can revisit this some time in future.

@posxposy
Copy link
Author

I'm inclined to go the opposite way and restrict @:using to enums.

Please, noooo :(
It is very useful for class types too. I'm using it in my project and I really like this feature.

@nadako
Copy link
Member

nadako commented Mar 20, 2019

But you can just add your usings to import.hx...

@posxposy
Copy link
Author

posxposy commented Mar 20, 2019

But you can just add your usings to import.hx...

Yes, but you can do the same for enums... Why do you need @:using then?
It is just good when you have a syntax sugar and different solutions for one problem.
import.hx doing it in a bit implicit way.

@back2dos
Copy link
Member

Dunno. When I proposed this, I specifically mentioned interfaces as a use case. And quite frankly, I don't get it: if you can apply the same extensions via using "globally" in import.hx, then what different kind of problem arises when applying them via @:using?

As for "why not just use import.hx":

@Gama11
Copy link
Member

Gama11 commented Apr 18, 2019

#8188

@Gama11 Gama11 closed this as completed Apr 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants