D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20091 - nogc callback inferred as non-nogc
Summary: nogc callback inferred as non-nogc
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-29 22:32 UTC by Ali Ak
Modified: 2024-12-13 19:04 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Ali Ak 2019-07-29 22:32:23 UTC
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");
Comment 1 Ali Ak 2019-07-29 23:21:16 UTC
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();
	}

}
Comment 2 dlangBugzillaToGithub 2024-12-13 19:04:45 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19603

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB