Bug 2276 – Error message missing line number on array operation

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2008-08-09T12:17:00Z
Last change time
2014-03-01T00:36:33Z
Keywords
diagnostic, patch
Assigned to
clugdbug
Creator
simen.kjaras

Comments

Comment #0 by simen.kjaras — 2008-08-09T12:17:56Z
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.
Comment #1 by clugdbug — 2009-06-08T19:17:38Z
This is much the same as bug 2277.
Comment #2 by clugdbug — 2010-05-18T00:12:06Z
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; }
Comment #3 by bugzilla — 2010-05-31T19:02:33Z