www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5184] New: throw ClassName.templatedStaticMethod(...) cannot be parsed

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

           Summary: throw ClassName.templatedStaticMethod(...) cannot be
                    parsed
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: kiki kmonos.net



The following code doesn't compile (in dmd 2.050 and 1.065), but I think it
should.

class Factory
{
    static Exception create(T)(T x)
    {
        return new Exception("whatever");
    }
}

void main()
{
    throw Factory.create(123);
}

Error message is the following:

 test.d(11): Error: type Factory is not an expression
Either one of the changes dissolves the compilation failure: - Changing the method declaration into a non-template create(int x) - Decomposing the throw statement as auto e = Factory.create(123); throw e; The combination of throw+static+template seems causing a trouble. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 07 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5184




Created an attachment (id=941)
A patch to fix the issue

What was happening was:

1. Factory.create(123) is desugared into CommaExp: (Factory,
Factory.create(123)).
   This is done in CallExp::semantic when the method is static template method.
   I'm not at all sure but is this for keeping side-effects for some cases?

2. In e2ir.c TypeExp::toElem emits the compilation error; it tries to compile
   lhs and rhs into IR, but TypeExp cannot be compiled to IR.

The patch modifies the first point. If the expression is "TYPE . SOMETHING",
the CommaExp insertion is disabled.

FYI, the problematic error is issued only inside ThrowStatement, because
in ThrowStatement::semantic, exp->optimize() is not called.
In, e.g., ReturnStatement::semantic optimizes away the TypeExp before toIR
convertion, so it won't cause any problem. (I don't know the reason why.)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 09 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5184


Kenji Hara <k.hara.pg gmail.com> changed:

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



https://github.com/D-Programming-Language/dmd/commit/5011154cdb4e9d48f4a866b18defb2b03f93a2b2

https://github.com/D-Programming-Language/dmd/commit/fdca0001179a43a188f3c003bf2b50757e250403

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 17 2011