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

extern/generic/abstract generates invalid code #5110

Closed
jonigata opened this issue Apr 14, 2016 · 2 comments · Fixed by #11551
Closed

extern/generic/abstract generates invalid code #5110

jonigata opened this issue Apr 14, 2016 · 2 comments · Fixed by #11551
Assignees
Labels
bug platform-cs Everything related to c# test-disabled
Milestone

Comments

@jonigata
Copy link

compile.hxml

-cs tmp
-main AbstractExtern
-D no-compilation
-D no-root

AbstractExtern.hx

@:native('System.Collections.Generic.List')
extern class CSharpList<T> {
    public var Count(default, null): Int;
    public function get_Item(n: Int): T;

}

abstract List<T>(CSharpList<T>) from CSharpList<T> to CSharpList<T> {
    public var Count(get, never): Int;
    public function get_Count(): Int {
        var l: CSharpList<T> = this;
        return l.Count;
    }
    public function get_Item(n: Int): T {
        var l: CSharpList<T> = this;
        return l.get_Item(n);
    }
}

class AbstractExtern {
    public static var l: List<Int>;

    public static function main() {
        trace(l.get_Item(3));
    }
}

generated code(partial)

        public static void main() {
            unchecked {
                #line 24 "/Users/life2bits/Grande/client/haxe/SandBox/externabstract/AbstractExtern.hx"
                global::haxe.Log.trace.__hx_invoke2_o(((double) (global::_AbstractExtern.List_Impl_[$type_param, global::haxe.root.AbstractExtern.l, 3]) ), global::haxe.lang.Runtime.undefined, default(double), new global::haxe.lang.DynamicObject(new int[]{302979532, 1547539107, 1648581351}, new object[]{"main", "AbstractExtern", "AbstractExtern.hx"}, new int[]{1981972957}, new double[]{((double) (24) )}));
            }
            #line default
        }

What is $type_param?

@Simn Simn added the platform-cs Everything related to c# label Apr 14, 2016
@nadako
Copy link
Member

nadako commented May 21, 2016

Somewhat reduced example:

abstract List<T>(cs.system.collections.generic.List_1<T>) {
    public function get_Item(n:Int):T {
        return this.get_Item(n);
    }
}

class Main {
    public static function main() {
        var l:List<Int> = null;
        var v = l.get_Item(3);
    }
}

generated code:

global::_Main.List_Impl_[$type_param, ((global::System.Collections.Generic.List<int>) (null) ), ((int) (3) )];

Looks like the issue here is that get_Item shouldn't be generated as a [] operator for abstract implementations. The $type_param argument is an internal hack for generating concrete T for call<T>() based on expected type (since Haxe doesn't support call<T>(...) syntax).

@waneck are we going to do something about this for 3.3?

@waneck
Copy link
Member

waneck commented May 26, 2016

Unfortunately not that simple to fix - we need to change all these special names because otherwise C# thinks they are operators and doesn't let us call them anyway

@waneck waneck modified the milestones: 3.4, 3.3.0-rc1 May 26, 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug platform-cs Everything related to c# test-disabled
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants