Bug 2483 – DMD allows assignment to a scope variable

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2008-12-01T12:58:00Z
Last change time
2015-06-09T05:11:45Z
Keywords
accepts-invalid, patch
Assigned to
yebblies
Creator
snake.scaly

Comments

Comment #0 by snake.scaly — 2008-12-01T12:58:01Z
The specs at http://www.digitalmars.com/d/1.0/attribute.html#scope say: "Assignment to a scope, other than initialization, is not allowed." Nevertheless, the following code compiles: void main() { scope Object foo; foo = new Object; } Tested this in DMD 1.037, DMD 2.021, 2.019 and 1.033.
Comment #1 by verylonglogin.reg — 2012-01-22T06:10:28Z
This bug leads to not calling destructor for the stack object and deleting the last heap object instead: --- import std.stdio; scope class C { int n; this(int n) { writefln(" this(%s) at %s", this.n = n, cast(void*)this); } ~this() { writefln("~this(%s) at %s", n, cast(void*)this); } } void main() { int i; writefln("Stack is at %s", &i); writefln("Heap is at %s", (new void[1]).ptr); { scope C c = new C(1); // at stack, never destroyed c = new C(2); // at heap, destroyed on collect c = new C(3); // ditto c = new C(4); // at heap, destroyed on scope exit } writeln("after scope"); } ---
Comment #2 by verylonglogin.reg — 2012-01-22T06:22:40Z
*** Issue 4214 has been marked as a duplicate of this issue. ***
Comment #3 by yebblies — 2012-01-29T21:31:05Z
Comment #4 by github-bugzilla — 2012-01-30T12:22:23Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/bf643d14c983395810c555b81cf375ebf3626ed0 Merge pull request #659 from yebblies/issue2483 Issue 2483 - DMD allows assignment to a scope variable
Comment #5 by github-bugzilla — 2012-01-30T12:24:53Z