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

@:generic leaks type parameters #4599

Open
waneck opened this issue Oct 21, 2015 · 6 comments
Open

@:generic leaks type parameters #4599

waneck opened this issue Oct 21, 2015 · 6 comments
Milestone

Comments

@waneck
Copy link
Member

waneck commented Oct 21, 2015

The following code:

class Main {
  static function main() {
    Test2.somethingElse(10);
  }
}

class Test {
  @:generic public static function something<T>(t:T) {
    return t;
  }
}

@:forward
abstract Test2(Test) {
  @:extern inline public static function somethingElse<T>(t:T) {
    return Test.something(t);
  }
}

Will generate the following -D dump for Test.something:

    static public something_somethingElse_T(method) : t : somethingElse.T -> somethingElse.T

     = function(t:somethingElse.T) = {
        var tmp = t;
        return tmp;
    }

That somethingElse.T comes from the abstract type

@waneck
Copy link
Member Author

waneck commented Oct 21, 2015

Also unfortunately there's no way to call a @:generic function from another function - be it @:generic or inline.
And since @:forward doesn't work for static fields, there's no way to correctly deal with wrapping a type on an abstract if it has static fields/functions

@Simn
Copy link
Member

Simn commented Oct 21, 2015

Isn't this just another instance of #3033?

@waneck
Copy link
Member Author

waneck commented Oct 21, 2015

It's not. This one has to do with @:generic types being generated with leaked type parameters - it has nothing to do with TMono types

@Simn
Copy link
Member

Simn commented Nov 19, 2015

It's probably the same as #3663. We expand @:generic while typing the inline function, so this is technically consistent.

@Simn
Copy link
Member

Simn commented Nov 25, 2015

It's not quite the same: #3663 is about inlining while generically expanding whereas this issue is about generically expanding while inlining.

@Simn Simn modified the milestone: 3.4 Feb 23, 2016
@Simn Simn modified the milestones: 3.4, 4.0 Jan 9, 2017
@Simn Simn modified the milestones: Release 4.0, Bugs Apr 17, 2018
@Simn Simn modified the milestones: Bugs, Later Mar 24, 2023
@Simn
Copy link
Member

Simn commented Jul 19, 2023

One solution for this might be to allow partial generic expansion. Basically, if we substitute a generic type parameter with a non-generic one, we absorb that type parameter into the new function and make the function @:generic again.

This would require reapplying calls to generic functions, but I think this is exactly the same situation as overload calls for which we already do that anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants