Thread overview
[Issue 2276] New: Error message missing line number, wrong variable names
Aug 09, 2008
d-bugmail
[Issue 2276] Error message missing line number on array operation
Jun 09, 2009
Don
May 18, 2010
Don
Jun 01, 2010
Walter Bright
August 09, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2276

           Summary: Error message missing line number, wrong variable names
           Product: D
           Version: 2.018
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: simen.kjaras@gmail.com


This program:

void main()
{
        int[] a = [0];
        int[] b = [1, 2];
        int[] c;
        c[] = a + b;
}

Gives the error message "Error: cannot implicitly convert expression (c0 + c1) of type int[] to int". While I agree the program is flawed, so is the error message.


-- 

June 09, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2276


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au
         AssignedTo|nobody@puremagic.com        |clugdbug@yahoo.com.au
            Summary|Error message missing line  |Error message missing line
                   |number, wrong variable      |number on array operation
                   |names                       |




--- Comment #1 from Don <clugdbug@yahoo.com.au>  2009-06-08 19:17:38 PDT ---
This is much the same as bug 2277.

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


Don <clugdbug@yahoo.com.au> changed:

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


--- Comment #2 from Don <clugdbug@yahoo.com.au> 2010-05-18 00:12:06 PDT ---
Arrays ops still need more work, but this patch at least gives reasonable error messages for everything it cannot handle, rather than generating errors on compiler-generated code. This also fixes bug 3548, which is largely the same as this one.

PATCH:
arrayop.c.
----------------
Expression *BinExp::arrayOp(Scope *sc)
{
    //printf("BinExp::arrayOp() %s\n", toChars());

    if (type->toBasetype()->nextOf()->toBasetype()->ty == Tvoid)
    {
        error("Cannot perform array operations on void[] arrays");
        return new ErrorExp();
    }
+    if (!isArrayOpValid(e2))
+    {
+        e2->error("invalid array operation %s (did you forget a [] ?)",
toChars());
+        return new ErrorExp();
+    }
----------------
and add the following function to the top of that file.
----------------
// Check that there are no uses of arrays without [].
bool isArrayOpValid(Expression *e)
{
    if (e->op == TOKslice)
        return true;
    Type *tb = e->type->toBasetype();

    if ( (tb->ty == Tarray) || (tb->ty == Tsarray) )
    {
        switch (e->op)
        {
            case TOKadd:
            case TOKmin:
            case TOKmul:
            case TOKdiv:
            case TOKmod:
            case TOKxor:
            case TOKand:
            case TOKor:
            case TOKpow:
                 return isArrayOpValid(((BinExp *)e)->e1) &&
isArrayOpValid(((BinExp *)e)->e2);
            case TOKcall:
                 return false; // TODO: Decide if [] is required after arrayop
calls.
            case TOKneg:
            case TOKtilde:
                 return isArrayOpValid(((UnaExp *)e)->e1);
            default:
                return false;
        }
    }
    return true;
}

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


Walter Bright <bugzilla@digitalmars.com> changed:

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


--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2010-05-31 19:02:33 PDT ---
http://www.dsource.org/projects/dmd/changeset/509

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