[Issue 9633] New: compiles trait wrongly returns true even when object method call actually does not compile

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Mar 2 08:37:55 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9633

           Summary: compiles trait wrongly returns true even when object
                    method call actually does not compile
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: puneet at coverify.org


--- Comment #0 from Puneet Goel <puneet at coverify.org> 2013-03-02 08:37:46 PST ---
The following code prints "baz compiles in global scope" with version 2.063. No
message is printed with version 2.062.

baz is an object method and does not compile in module scope since no (this
pointer) object has been provided as argument. So compiles trait on line 11
should return false, as is done by DMD version 2.062.

class Foo {                                              // 1 
  void baz() {}                                          // 2
  void bar() {                                           // 3
    static if(compilesWithoutThis!baz) {                 // 4
      import std.stdio;                                  // 5
      writeln("baz compiles in global scope");           // 6
    }                                                    // 7
  }                                                      // 8
}                                                        // 9
template compilesWithoutThis (alias F) {                 // 10
  static if(__traits(compiles, F()))                     // 11
    enum bool compilesWithoutThis = true;                // 12
  else                                                   // 13
    enum bool compilesWithoutThis = false;               // 14
}                                                        // 15
void main() {                                            // 16
  Foo foo = new Foo;                                     // 17
  foo.bar();                                             // 18
}                                                        // 19

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


More information about the Digitalmars-d-bugs mailing list