Thread overview
[Issue 1324] Wrong module name in exception when using mixin
Jul 30, 2014
Ivan Kazmenko
Jul 30, 2014
Ivan Kazmenko
[Issue 1324] __FILE__ in mixin template expand to the definition, not the instantiation
Aug 12
RazvanN
6 days ago
RazvanN
July 30, 2014
https://issues.dlang.org/show_bug.cgi?id=1324

Ivan Kazmenko <gassa@mail.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=13229

--
July 30, 2014
https://issues.dlang.org/show_bug.cgi?id=1324

Ivan Kazmenko <gassa@mail.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gassa@mail.ru

--
May 21
https://issues.dlang.org/show_bug.cgi?id=1324

Mathias LANG <pro.mathias.lang@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|diagnostic                  |
                 CC|                            |pro.mathias.lang@gmail.com
           Hardware|x86                         |All
            Version|D1 (retired)                |D2
            Summary|Wrong module name in        |__FILE__ in mixin template
                   |exception when using mixin  |expand to the definition,
                   |                            |not the instantiation
                 OS|Windows                     |All

--- Comment #1 from Mathias LANG <pro.mathias.lang@gmail.com> ---
Edited the issue title to make the current problem more obvious.
The original code uses ranges access to trigger an exception, which are errors
(not exception in D2).

The actual bug, can be illustrated by those 2 files:

///// t1.d /////
module t1;
import t2;
import std.stdio;
void main()
{
    mixin mixinT2!();
    testT2();
}

///// t2.d /////
module t2;
template mixinT2()
{
  void testT2()
  {
      try
          throw new Exception("FromT2");
      catch(Exception e)
          writefln("T2: caught exception in %s: '%s'", __FILE__, e.toString);
  }
}

///////////////
Running this code:

dmd t2.d -run t1.d
T2: caught exception in t2.d: 'object.Exception@t2.d(8): FromT2
----------------
??:? void t1.main().__mixin1.testT2(int) [0x102b84f17]
??:? _Dmain [0x102b84afb]'


As the message shows, `__FILE__` expands to `t2.d`, both in the `writeln` call
and the default parameter for `Exception` ctor.
However, the specs currently mentions:
> __FILE__ and __LINE__ expand to the source file name and line number at the point of instantiation. The path of the source file is left up to the compiler.

It is not 100% clear to me if "point of instantiation" implies templates as well, and thus not 100% clear if this is a bug and/or can be solved.

--
August 12
https://issues.dlang.org/show_bug.cgi?id=1324

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #2 from RazvanN <razvan.nitu1305@gmail.com> ---
(In reply to Mathias LANG from comment #1)
> Edited the issue title to make the current problem more obvious.
> The original code uses ranges access to trigger an exception, which are
> errors (not exception in D2).
> 
> The actual bug, can be illustrated by those 2 files:
> 
> ///// t1.d /////
> module t1;
> import t2;
> import std.stdio;
> void main()
> {
>     mixin mixinT2!();
>     testT2();
> }
> 
> ///// t2.d /////
> module t2;
> template mixinT2()
> {
>   void testT2()
>   {
>       try
>           throw new Exception("FromT2");
>       catch(Exception e)
>           writefln("T2: caught exception in %s: '%s'", __FILE__, e.toString);
>   }
> }
> 
> ///////////////
> Running this code:
> 
> dmd t2.d -run t1.d
> T2: caught exception in t2.d: 'object.Exception@t2.d(8): FromT2
> ----------------
> ??:? void t1.main().__mixin1.testT2(int) [0x102b84f17]
> ??:? _Dmain [0x102b84afb]'
> 
> 
> As the message shows, `__FILE__` expands to `t2.d`, both in the `writeln`
> call and the default parameter for `Exception` ctor.
> However, the specs currently mentions:
> > __FILE__ and __LINE__ expand to the source file name and line number at the point of instantiation. The path of the source file is left up to the compiler.
> 
> It is not 100% clear to me if "point of instantiation" implies templates as well, and thus not 100% clear if this is a bug and/or can be solved.

"Point of instantiation" refers to the call site of a function that uses __FILE__ as a default parameter. Even though the mixin introduces the code in there, I like it that __FILE__/__LINE__ point to the actual declaration because it's real code, that generated.

IMHO this bug report is invalid.

--
6 days ago
https://issues.dlang.org/show_bug.cgi?id=1324

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--