www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2887] New: Wrong line number reported inside string mixin

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2887

           Summary: Wrong line number reported inside string mixin
           Product: D
           Version: 1.041
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: cbkbbejeap mailinator.com


----------
import tango.io.Stdout;
template line()
{
        const char[] line = "__LINE__";
}
template wrongLine()
{
        const char[] wrongLine = "\n\n\n\n\n__LINE__";
}
void main()
{
        Stdout.formatln("Line: {}, {}, {}", __LINE__, mixin(line!()),
mixin(wrongLine!()));
        Stdout.formatln("Line: {}, {}, {}", __LINE__, mixin(line!()),
mixin(wrongLine!()));
}
----------

Expected output:
Line: 12, 12, 12
Line: 13, 13, 13

Actual output:
Line: 12, 12, 17
Line: 13, 13, 18

DMD is reporting the line where __LINE__ *would* be *after* mixin expansion.
However, this only hinders the programmer rather than helping because the
programmer isn't actually working with the post-expansion code. Therefore, when
__LINE__ appears inside a string mixin, it should resolve to the line number of
the mixin instantiation.

This is preventing my custom assert routines from automatically reporting the
correct line number of the assertion, and is thus forcing my custom assert
routines to require the user to manually pass in __LINE__.


-- 
Apr 24 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2887







What I think it should do is the filename inside a mixin should be (based on
outside values):

__FILE__:__LINE__

and the line number should restart at 1 so that you can get both inside and
outside info even with several levels of mixins

Another option would be to have a __LINES__ macro that is an array of line
numbers for each level of mixins.

__LINES__[$-2] == __LINE__ at mixin()


-- 
Apr 24 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2887




13:25:54 PDT ---
Workaround:

template foo()
{
  const char[] foo =
`{ auto __foo_line = __LINE__; // must be on first line
// Also, the extra surrounding {} is needed to
// allow foo to be used twice in the same scope.

Stdout.formatln("Foo:");
Stdout.formatln("  File {}", __FILE__);
Stdout.formatln("  Line {}", __foo_line);
}`;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 07 2009