www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3557] New: Pure function cannot call struct constructor

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

           Summary: Pure function cannot call struct constructor
           Product: D
           Version: 2.036
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: tomeksowi gmail.com



PST ---
struct A {
    float f;
    this (float f) {
        this.f = f;
    }
    static pure A stworz(float f) {
        return A(f);
    }
}

The above doesn't compile:
Error: pure function 'stworz' cannot call impure function 'this'

What's interesting, if stworz signature is one of the below:

static pure stworz(float f);
static pure auto stworz(float f);

then it merrily compiles. So it's sth about the explicit return type.

If I remove the constructor, it also compiles.
If A is a class, it also compiles.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 29 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3557


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
                 CC|                            |clugdbug yahoo.com.au



It shouldn't compile, since the constructor isn't marked as pure. But if you
mark the constructor as pure:

 pure {
     this (float f) {
        this.f = f;
    }
 }

you get:
bug.d(14): Error: cannot modify const/immutable/inout expression this.f

So we definitely have a problem.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 10 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3557




PST ---

 It shouldn't compile, since the constructor isn't marked as pure. But if you
 mark the constructor as pure:
 
  pure {
      this (float f) {
         this.f = f;
     }
  }
 
 you get:
 bug.d(14): Error: cannot modify const/immutable/inout expression this.f
 
 So we definitely have a problem.
Yes, I had a feeling compiler should let me have pure ctors.. What about the problem I mentioned at the bottom (if A is a class): class A { float f; this (float f) { // NOT pure this.f = f; } static pure A stworz(float f) { return new A(f); } } This compiles. Should it? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 11 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3557




PST ---

 This compiles. Should it?
I'm now confident it shouldn't: string global; class A { float f; this (float f) { // NOT pure this.f = f; global = "BUGABUGA!"; } static pure A stworz(float f) { return new A(f); } } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 11 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3557


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Pure function cannot call   |Struct constructors cannot
                   |struct constructor          |be declared as pure





 This compiles. Should it?
I'm now confident it shouldn't: string global; class A { float f; this (float f) { // NOT pure this.f = f; global = "BUGABUGA!"; } static pure A stworz(float f) { return new A(f); } }
That's bug 3573. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 12 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3557


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies gmail.com
         Resolution|                            |FIXED



Marking constructors as pure works in current dmd (2.054).

I've put the other case as Issue 6320

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