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

nogc callback inferred as non-nogc #19603

Open
dlangBugzillaToGithub opened this issue Jul 29, 2019 · 1 comment
Open

nogc callback inferred as non-nogc #19603

dlangBugzillaToGithub opened this issue Jul 29, 2019 · 1 comment

Comments

@dlangBugzillaToGithub
Copy link

Ali Ak reported this on 2019-07-29T22:32:23Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=20091

CC List

Description

import std;

struct W(T) {
    T value;
    auto hook(handlers...)() {
        return handlers[0](value);
    }
}

template f(handlers...) {
    auto ref f(T)(auto ref T value) {
        return value.hook!handlers;
    }
}

@nogc void main() {
    auto a = W!int(3);
    auto b = a.f!((_) => "yes");
}

Produces: Error: @nogc function D main cannot call non-@nogc function onlineapp.main.f!(W!int).f

Adding @nogc on function f says hook!((_) => "yes").hook closes over variable __this310

If you explicitly specify a type on the lambda that you pass to f then it compiles:

auto b = a.f!((int) => "yes");
@dlangBugzillaToGithub
Copy link
Author

ali.akhtarzada commented on 2019-07-29T23:21:16Z

f's instantiation with untyped lambda:

f!(W!int)
{
	auto pure nothrow @safe string f(ref W!int value)
	{
		return (void*[2] __this3 = null;) , value.hook();
	}

}

With typed lambda:

f!(W!int)
{
	auto pure nothrow @nogc @safe string f(ref W!int value)
	{
		return value.hook();
	}

}

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

1 participant