Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
November 29, 2009 [Issue 3557] New: Pure function cannot call struct constructor | ||||
---|---|---|---|---|
| ||||
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 --- Comment #0 from Tomasz Sowiński <tomeksowi@gmail.com> 2009-11-29 03:19:44 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: ------- |
January 10, 2010 [Issue 3557] Pure function cannot call struct constructor | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomasz Sowiński | 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 --- Comment #1 from Don <clugdbug@yahoo.com.au> 2010-01-10 11:54:44 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 11, 2010 [Issue 3557] Pure function cannot call struct constructor | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomasz Sowiński | http://d.puremagic.com/issues/show_bug.cgi?id=3557 --- Comment #2 from Tomasz Sowiński <tomeksowi@gmail.com> 2010-01-11 13:33:40 PST --- (In reply to comment #1) > 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: ------- |
January 11, 2010 [Issue 3557] Pure function cannot call struct constructor | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomasz Sowiński | http://d.puremagic.com/issues/show_bug.cgi?id=3557 --- Comment #3 from Tomasz Sowiński <tomeksowi@gmail.com> 2010-01-11 13:40:33 PST --- (In reply to comment #2) > 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: ------- |
January 12, 2010 [Issue 3557] Struct constructors cannot be declared as pure | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomasz Sowiński | 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 --- Comment #4 from Don <clugdbug@yahoo.com.au> 2010-01-12 02:20:30 PST --- (In reply to comment #3) > (In reply to comment #2) > > 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: ------- |
July 15, 2011 [Issue 3557] Struct constructors cannot be declared as pure | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomasz Sowiński | 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 --- Comment #5 from yebblies <yebblies@gmail.com> 2011-07-15 14:19:25 EST --- 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: ------- |
Copyright © 1999-2021 by the D Language Foundation