Chapel: Improve compiler message for incorrectly assigning associative domain to array

Created on 24 Jan 2020  路  5Comments  路  Source: chapel-lang/chapel

Is it reasonable to get a compiler error to emit a better message on arr2 below? Jumping between multiple languages has caused me to write it and I was perplexed on what the problem is. The result was a change in syntax (to arr3) and not counting related.

var arr1: [0..3] int = {0..3};
var arr2: [0..3] int = {0, 1, 2, 3};
var arr3: [0..3] int = [0, 1, 2, 3];
error: tuple size must match the number of grouped variables

chpl version 1.20.0

Compiler Error Message user issue

Most helpful comment

I've opened PR #14928 as a placeholder for resolving this issue, but would appreciate thoughts on whether the proposed error message is sufficiently clear or not.

All 5 comments

Note: Error emitted on arr2.

@ben-albrecht while working around, I also found out that the following code does not give a compile-time error.

var arr3: [0..3] int = [0, 1, 2, 3, 5];

The function that compares the no of variables and the tuple size is implemented in modules/internal/ChapelTuple.chpl and is as follows

  pragma "no doc"
  proc _check_tuple_var_decl(x: _tuple, param p) param {
    if p == x.size {
      return true;
    } else {
      compilerError("tuple size must match the number of grouped variables");
      return false;
    }
  }
  pragma "no doc"
  proc _check_tuple_var_decl(x, param p) param {
    compilerError("illegal tuple variable declaration with non-tuple initializer");
    return false;
  }

According to the above implementation var arr3: [0..3] int = [0, 1, 2, 3, 5]; is expected to throw an error? I am not sure why is it not throwing one?

Thanks!

@Aniket21mathur - While the error message for the above examples is about tuples, these are actually array assignment (hence why it's a bad error message). For your example, even though these array sizes are hard-coded in the source code, the compiler treats the array sizes as runtime values, and therefore does not raise a compile-time error.

It would be reasonable to spin this particular class of error messages off into a separate issue, if you're up to it.

Is it reasonable to get a compiler error to emit a better message on arr2 below?

@BryantLam: It's completely reasonable. I've currently got a trivial change that makes the error message into error: cannot assign to rectangular arrays from associative domains. Does that seem OK, or do you / does anyone have a better suggestion?

I've opened PR #14928 as a placeholder for resolving this issue, but would appreciate thoughts on whether the proposed error message is sufficiently clear or not.

Was this page helpful?
0 / 5 - 0 ratings