Jump to page: 1 2
Thread overview
[Issue 5080] New: breaking const-correctness with class/interface
Oct 19, 2010
Kenji Hara
Oct 19, 2010
Kenji Hara
Oct 19, 2010
Kenji Hara
Oct 19, 2010
Kenji Hara
Oct 19, 2010
Kenji Hara
Jan 07, 2011
Tomasz Sowiński
Feb 06, 2011
Brad Roberts
Feb 09, 2011
Don
Jan 31, 2012
yebblies
October 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5080

           Summary: breaking const-correctness with class/interface
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: k.hara.pg@gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg@gmail.com> 2010-10-19 04:28:46 PDT ---
Result of attached test code is follows:
----
part1 ----
true,   false,  false,  false,  false
true,   true,   false,  false,  true
false,  false,  true,   true,   false
false,  false,  true,   true,   false
false,  false,  false,  false,  true
part2 ----
true,   false,  false,  false,  false
true,   true,   false,  false,  true
false,  false,  true,   true,   false
false,  false,  true,   true,   false
false,  false,  false,  false,  true
part3 ----
true,   true,   true,   true,   true
true,   true,   true,   true,   true
true,   true,   true,   true,   true
true,   true,   true,   true,   true
true,   true,   true,   true,   true
----

I discovered two issues.

Part 1 & 2:
  Shared const should not be implicitly convertible to shared, is it?
Part 3:
  All of them are completely broken.

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



--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2010-10-19 04:30:48 PDT ---
Created an attachment (id=786)
test code

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


bearophile_hugs@eml.cc changed:

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


--- Comment #2 from bearophile_hugs@eml.cc 2010-10-19 04:58:23 PDT ---
By the way, you have just shown the right way to design (or test) a language: you need to test all the items in the matrix/tensor of all possible combinations. One of the the inventor of Java did the same.

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



--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> 2010-10-19 08:08:39 PDT ---
This code should not work.
----
interface I
{
    void set(int v);
}
class A : I
{
    this(int v){val = v;}
    int val = 10;
    override void set(int v){val = v;}
}
void change(I i)
{
    i.set(100);
}
void main()
{
    auto a = new immutable(A)(10);
    assert(a.val == 10);
    change(a);              // immutable(A) is converted to (mutable) I.
    assert(a.val == 100);   // breaking const-correctness!
}
----

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



--- Comment #4 from Kenji Hara <k.hara.pg@gmail.com> 2010-10-19 10:23:14 PDT ---
Created an attachment (id=787)
test code(fixed)

test code fixed.
I withdraw part 1 and 2.

test code result is follows:
----
part1 ----
true,   false,  false,  false,  false
true,   true,   false,  false,  true
false,  false,  true,   false,  false
false,  false,  true,   true,   true
false,  false,  false,  false,  true
part2 ----
true,   false,  false,  false,  false
true,   true,   false,  false,  true
false,  false,  true,   false,  false
false,  false,  true,   true,   true
false,  false,  false,  false,  true
part3 ----
true,   true,   true,   true,   true
true,   true,   true,   true,   true
true,   true,   true,   true,   true
true,   true,   true,   true,   true
true,   true,   true,   true,   true
----

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



--- Comment #5 from Kenji Hara <k.hara.pg@gmail.com> 2010-10-19 10:26:44 PDT ---
Created an attachment (id=788)
Patch for DMD svn r716

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


Tomasz Sowiński <tomeksowi@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tomeksowi@gmail.com


--- Comment #6 from Tomasz Sowiński <tomeksowi@gmail.com> 2011-01-07 14:30:10 PST ---
(In reply to comment #3)
> interface I
> {
>     void set(int v);
> }
> class A : I
> {
>     this(int v){val = v;}
>     int val = 10;
>     override void set(int v){val = v;}
> }
> void change(I i)
> {
>     i.set(100);
> }
> void main()
> {
>     auto a = new immutable(A)(10);
>     assert(a.val == 10);
>     change(a);              // immutable(A) is converted to (mutable) I.
>     assert(a.val == 100);   // breaking const-correctness!
> }

Looks like duplicate of bug 3731 (read Steven's comment).

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


Brad Roberts <braddr@puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Platform|x86_64                      |x86


--- Comment #7 from Brad Roberts <braddr@puremagic.com> 2011-02-06 15:38:47 PST ---
Mass migration of bugs marked as x86-64 to just x86.  The platform run on isn't what's relevant, it's if the app is a 32 or 64 bit app.

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



--- Comment #8 from Don <clugdbug@yahoo.com.au> 2011-02-09 08:27:11 PST ---
The patch causes this code to fail to compile:
----
class S { }

void main()
{
    S s1 = new S;
    const S s2 = new S;
    assert(s1!=s2);
}
---
Even so, I think the patch is probably correct -- it's a problem with opEquals. But this means that more work is required before this patch could be applied.

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


Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com


--- Comment #9 from Steven Schveighoffer <schveiguy@yahoo.com> 2011-02-09 10:18:44 PST ---
(In reply to comment #8)
> The patch causes this code to fail to compile:
> ----
> class S { }
> 
> void main()
> {
>     S s1 = new S;
>     const S s2 = new S;
>     assert(s1!=s2);
> }
> ---
> Even so, I think the patch is probably correct -- it's a problem with opEquals. But this means that more work is required before this patch could be applied.

That code should fail to compile on the current compiler without patches, because the prototype for opEquals for objects is:

bool opEquals(Object lhs, Object rhs);

Clearly, this should not accept any const objects.  Because opEquals is special somehow, the compiler rams it through.

So yeah, that code is not indicative of the patch being bad.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2