www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2483] New: DMD allows assignment to a scope variable

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

           Summary: DMD allows assignment to a scope variable
           Product: D
           Version: 1.037
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: snake.scaly gmail.com


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.


-- 
Dec 01 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2483


Denis <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |verylonglogin.reg gmail.com
            Version|1.037                       |D1 & D2


--- Comment #1 from Denis <verylonglogin.reg gmail.com> 2012-01-22 17:10:28 MSK
---
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");
}
---

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


Denis <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #2 from Denis <verylonglogin.reg gmail.com> 2012-01-22 17:22:40 MSK
---
*** Issue 4214 has been marked as a duplicate of this issue. ***

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


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |yebblies gmail.com
           Platform|x86                         |All
         OS/Version|Windows                     |All


--- Comment #3 from yebblies <yebblies gmail.com> 2012-01-30 16:31:05 EST ---
https://github.com/D-Programming-Language/dmd/pull/659

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



--- Comment #4 from github-bugzilla puremagic.com 2012-01-30 12:22:23 PST ---
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

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



--- Comment #5 from github-bugzilla puremagic.com 2012-01-30 12:24:53 PST ---
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/b0f5018d1c28cf1129c5eeb111262dbcf4a13d02
fix Issue 2483 - DMD allows assignment to a scope variable

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


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