D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7339 - [2.058] std.string.indexOf doesn't instantiate with inlining
Summary: [2.058] std.string.indexOf doesn't instantiate with inlining
Status: RESOLVED DUPLICATE of issue 7199
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 regression
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on: 4724
Blocks:
  Show dependency treegraph
 
Reported: 2012-01-21 12:08 UTC by David Simcha
Modified: 2012-01-24 12:34 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 David Simcha 2012-01-21 12:08:17 UTC
This is related to Bug 4724, but I'm filing it as a separate issue and labeling it a regression because something (probably the more aggressive inlining that was added for 2.058) expands the effects of that bug in ways that break previously working code.  If we can't fix the compiler bug then we need to work around it to avoid an awful regression.

import std.string;

void main() {
    "".indexOf("");
}

dmd -O -inline -release -c test.d
/home/dsimcha/dmd2/linux/bin64/../../src/phobos/std/algorithm.d(2970): Error: function std.string.indexOf!(char,char).indexOf.simpleMindedFind!(__lambda6,const(char)[],const(char)[]).simpleMindedFind is a nested function and cannot be accessed from main

Here's a reduced version that doesn't import any Phobos modules:

void main() {
    "".indexOf("") ;
}

void indexOf(const(char)[] s, const(char)[] sub) {
    find!((dchar a, dchar b){return a == b;})
        (s, sub);
}

void find(alias pred)(const(char)[] haystack, const(char)[] needle) {
     pred(haystack[0], needle[0]);
}

$ dmd -c -O -inline -release test.d
test.d(11): Error: function test.indexOf.find!(delegate pure nothrow @safe bool(dchar a, dchar b)
{
return cast(uint)a == cast(uint)b;
}
).find is a nested function and cannot be accessed from main
Comment 1 Don 2012-01-24 12:34:40 UTC

*** This issue has been marked as a duplicate of issue 7199 ***