D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6501 - import inside of eponymous template does not work correctly
Summary: import inside of eponymous template does not work correctly
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-15 20:35 UTC by Jonathan M Davis
Modified: 2012-02-14 06:10 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jonathan M Davis 2011-08-15 20:35:34 UTC
This code

template eponymous(string str)
{
    import std.metastrings;

    enum eponymous = Format!("%s", str);
}

void main()
{
    pragma(msg, eponymous!("message"));
}

incorrectly prints this during compilation:

eponymous!("message")

whereas if you move the import outside of the template, it correctly prints

message
Comment 1 kennytm 2011-08-16 06:49:05 UTC
This is because the template has more than one member. Those symbols imported from std.metastrings can now be accessed from the template, e.g.

--------------
pragma(msg, eponymous!"message".Format);
// prints "template Format(A...)"
pragma(msg, eponymous!"message".eponymous);
// prints "message"
--------------

Perhaps this is by-design.
Comment 2 Jonathan M Davis 2011-08-16 10:30:01 UTC
Per TDPL, eponymous templates are supposed to be able to have multiple members (but just one with the same name as the template). So, if that's the issue here, it's a bug related to not yet fully following TDPL.
Comment 3 Martin Nowak 2012-02-14 06:10:57 UTC
cat > a.d << CODE
template eponymous(string str)
{
    import std.metastrings;

    enum eponymous = Format!("%s", str);
}

void main()
{
    pragma(msg, eponymous!("message"));
}
CODE

dmd -c a.d