www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Strange error happens only with -inline flag

reply "finalpatch" <fengli gmail.com> writes:
The following code compiles fine with the command "dmd test.d"

import std.array, std.algorithm, std.algorithm, std.string;
void main()
{
	int[string] s;
	auto a = join(map!(a=>format("%s %d", a, s[a]))(s.keys));
}

However, if I try to compile it with "dmd -inline test.d", I get 
this error message:

test.d(5): Error: function D main is a nested function and cannot 
be accessed from std.array.join!(MapResult!(__lambda2, 
string[])).join

Isn't -inline supposed to be completely transparent?
Jun 12 2013
next sibling parent "finalpatch" <fengli gmail.com> writes:
On Thursday, 13 June 2013 at 06:06:10 UTC, finalpatch wrote:
 The following code compiles fine with the command "dmd test.d"

 import std.array, std.algorithm, std.algorithm, std.string;
 void main()
 {
 	int[string] s;
 	auto a = join(map!(a=>format("%s %d", a, s[a]))(s.keys));
 }

 However, if I try to compile it with "dmd -inline test.d", I 
 get this error message:

 test.d(5): Error: function D main is a nested function and 
 cannot be accessed from std.array.join!(MapResult!(__lambda2, 
 string[])).join

 Isn't -inline supposed to be completely transparent?

This happens with DMD 2.063. LDC 0.11 compiles this code with -inline or -O3 just fine.
Jun 12 2013
prev sibling next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Thursday, June 13, 2013 08:06:06 finalpatch wrote:
 The following code compiles fine with the command "dmd test.d"
 
 import std.array, std.algorithm, std.algorithm, std.string;
 void main()
 {
 	int[string] s;
 	auto a = join(map!(a=>format("%s %d", a, s[a]))(s.keys));
 }
 
 However, if I try to compile it with "dmd -inline test.d", I get
 this error message:
 
 test.d(5): Error: function D main is a nested function and cannot
 be accessed from std.array.join!(MapResult!(__lambda2,
 string[])).join
 
 Isn't -inline supposed to be completely transparent?

Yes, inlining should have no effect on the semantics of the code, but the inliner is not bug-free. Please report any bugs you find: http://d.puremagic.com/issues - Jonathan M Davis
Jun 12 2013
prev sibling parent "David Nadlinger" <code klickverbot.at> writes:
On Thursday, 13 June 2013 at 06:10:56 UTC, finalpatch wrote:
 This happens with DMD 2.063. LDC 0.11 compiles this code with 
 -inline or -O3 just fine.

LDC does not employ the AST-based inliner DMD uses. David
Jun 13 2013