Thread overview
[Issue 3688] New: Can't have declaration with assignment to const/immutable inside if condition
Jan 07, 2010
Tomasz Sowiński
Apr 19, 2011
Kenji Hara
May 29, 2011
Walter Bright
Jun 01, 2011
Walter Bright
January 07, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3688

           Summary: Can't have declaration with assignment to
                    const/immutable inside if condition
           Product: D
           Version: 2.036
          Platform: All
        OS/Version: All
            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> 2010-01-07 14:47:07 PST ---
Should pass:

if (const int a = 4)  // Error: variable test.main.a cannot modify const
    assert (a==4);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 19, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3688


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
                 CC|                            |k.hara.pg@gmail.com
            Version|2.036                       |D2


--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2011-04-18 20:20:18 PDT ---
More comprehensive code.
----
struct S
{
    int v;
    this(int n) { v = n; }
    const bool opCast(T:bool)() { return true; }
}
void main()
{
    if (int a = 1)
        assert(a == 1);
    else assert(0);

    if (const int a = 2)
        assert(a == 2);
    else assert(0);

    if (immutable int a = 3)
        assert(a == 3);
    else assert(0);

    if (auto s = S(10))
        assert(s.v == 10);
    else assert(0);

    if (auto s = const(S)(20))
        assert(s.v == 20);
    else assert(0);

    if (auto s = immutable(S)(30))
        assert(s.v == 30);
    else assert(0);
}
----

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3688


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2011-05-29 10:33:45 PDT ---
See:

https://github.com/D-Programming-Language/dmd/pull/35

which needs more work.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 01, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3688


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2011-05-31 19:14:59 PDT ---
https://github.com/D-Programming-Language/dmd/commit/e921b529a022fda0e01153464fc0f91e83647ba5

https://github.com/D-Programming-Language/dmd/commit/e122d4ade8ebf7d117825494598e047369ebbe48

https://github.com/D-Programming-Language/dmd/commit/f84fb58a03456996cc579253901acce5b72a5138

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