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

recursive generic functions generates invalid code. #3523

Open
deltaluca opened this issue Oct 27, 2014 · 2 comments
Open

recursive generic functions generates invalid code. #3523

deltaluca opened this issue Oct 27, 2014 · 2 comments
Assignees
Milestone

Comments

@deltaluca
Copy link
Contributor

class Main
{
    static function main()
    {
        for_loop(4,
                function (x) return x < 10,
                function (x) return x + 1,
                function (x) trace("int   " + x));

        for_loop(4.0,
                function (x) return x < 10.0,
                function (x) return x + 1.0,
                function (x) trace("float   " + x));

        for_loop("",
                 function (x) return x.length < 10,
                 function (x) return x + "-",
                 function (x) trace("string  " + x));
    }

    @:generic static function for_loop<T>(v:T, condition:T->Bool, next:T->T, block:T->Void)
    {
        if (condition(v))
        {
            block(v);
            for_loop(next(v), condition, next, block);
        }
    }
}
haxe -D js_es5 -D analyzer -js main.js -main Main
(function () { "use strict";
var Main = function() { };
Main.for_loop_String = function(v,condition,next,block) {
    if(condition(v)) {
        block(v);
        Main.for_loop_for_loop_T(next(v),condition,next,block);
    }
};
Main.for_loop_Float = function(v,condition,next,block) {
    if(condition(v)) {
        block(v);
        Main.for_loop_for_loop_T(next(v),condition,next,block);
    }
};
Main.for_loop_Int = function(v,condition,next,block) {
    if(condition(v)) {
        block(v);
        Main.for_loop_for_loop_T(next(v),condition,next,block);
    }
};
Main.main = function() {
    Main.for_loop_Int(4,function(x) {
        return x < 10;
    },function(x1) {
        return x1 + 1;
    },function(x2) {
        console.log("int   " + x2);
    });
    Main.for_loop_Float(4.0,function(x3) {
        return x3 < 10.0;
    },function(x4) {
        return x4 + 1.0;
    },function(x5) {
        console.log("float   " + x5);
    });
    Main.for_loop_String("",function(x6) {
        return x6.length < 10;
    },function(x7) {
        return x7 + "-";
    },function(x8) {
        console.log("string  " + x8);
    });
};
Main.main();
})();
@Simn Simn self-assigned this Nov 18, 2014
@Simn Simn added this to the 3.3 milestone Nov 18, 2014
@Simn
Copy link
Member

Simn commented Nov 18, 2014

I"ve made it error in the recursive case for now, which is better than generating nonsense code.

I want to support this properly too, but it"s not trivial because it means delaying the generic expansion until the concrete types are available.

@Simn Simn modified the milestones: 3.4, 3.3 Jun 9, 2015
@Simn
Copy link
Member

Simn commented Jun 9, 2015

We can"t delay this at the moment because we lose the type parameter information. Fixing this is going to require AST changes (see https://groups.google.com/forum/#!topic/haxedev/M96qHOYCLsI).

@Simn Simn modified the milestones: 3.4, 4.0 Jan 9, 2017
@Simn Simn modified the milestones: Release 4.0, Backlog Apr 17, 2018
@Simn Simn modified the milestones: Backlog, Later Mar 24, 2023
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