www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4662] New: Array ops on const arrays

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

           Summary: Array ops on const arrays
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



This D2 program shows two problems (dmd 2.048):


void foo(const double[] arr1) {
    arr1[] += 1;      // line 2, no error here
    double[] arr2;
    arr1[] += arr2[]; // line 4, Error here
}
void main() {}


The first problem is at line 2, where the const nature of arr1 is ignored.

The second problem is at line 4, that generates a wrong error message:

test.d(4): Error: invalid array operation arr1[] += cast(const(double[]))arr2[]
(did you forget a [] ?)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 17 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4662


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dsimcha yahoo.com



*** Issue 7286 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 27 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4662


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
                 CC|                            |yebblies gmail.com
           Platform|x86                         |All
         AssignedTo|nobody puremagic.com        |yebblies gmail.com
         OS/Version|Windows                     |All



Looks like the fix for issue 5284 only got assignment.

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


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch



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

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




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/e917e1e404f8dc6b3440788d40fcf936c51bdf57
Fix Issue 4662 - Array ops on const arrays

For BinAssignExp, check that the lhs is assignable or mutable.

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


Issue 4662 - Array ops on const arrays

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




Additional fix for yebblies's patch:
https://github.com/D-Programming-Language/dmd/pull/1046

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




The two problems of the example seems fixed. Now this program:


void main() {
    const int[] a = new int[5];
    int[] b = new int[5];
    b[] += a[];
}


Gives:
test.d(4): Error: slice cast(const(int)[])b[] is not mutable

I think is a rejects-valid.

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





 The two problems of the example seems fixed. Now this program:
 
 
 void main() {
     const int[] a = new int[5];
     int[] b = new int[5];
     b[] += a[];
 }
 
 
 Gives:
 test.d(4): Error: slice cast(const(int)[])b[] is not mutable
 
 I think is a rejects-valid.
Yes, my mistake. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 15 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4662




Ok, not really my mistake, but a problem with typeMerge or the use of typeMerge
in BinAssignExp::semantic.  It doesn't make any sense for a BinAssignExp or a
BinAssignExp::e1 to be type-merged with the rhs, ever.

Bearophile, could you please open another bug for this?  It is a regression
because this bug previously hid the error.

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


bearophile_hugs eml.cc changed:

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




 Ok, not really my mistake, but a problem with typeMerge or the use of typeMerge
 in BinAssignExp::semantic.  It doesn't make any sense for a BinAssignExp or a
 BinAssignExp::e1 to be type-merged with the rhs, ever.
 
 Bearophile, could you please open another bug for this?  It is a regression
 because this bug previously hid the error.
OK, thank you for answering. I close this bug report as fixed, and I have opened a new regression, Issue 8390 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 15 2012