Skip to content

Poor error message when using array writes on non-array type #818

@quark17

Description

@quark17

I had instantiated mkCReg, which returns an array of interfaces, but then I changed my mind and made it an ordinary mkReg, but forgot to remove the brackets in some uses. The error message was not great. For example:

module mkTest();
  Reg#(Bool) rg <- mkRegU;

  rule rl;
    rg[0] <= True;
  endrule
endmodule

results in this error message:

Error: "Test.bsv", line 1, column 8: (T0098)
  Run-time writes with [] and <= for a value of type:
    Reg#(Bool)
  require an argument value of type:
    _tctyvar1262
  Instead, the following argument type was found:
    Bool
  Writes were performed on this type in or at the following locations:
    "Test.bsv", line 5, column 7

The position at the end of the message is correct, and the message does refer to array writes (with [] and <=), so it was possible to figure out the mistake; but the type variable name didn't need to be exposed to the user.

The array write syntax is implemented using a typeclass (PrimWriteable) and context errors for that class that are detected by BSC and reported specially, which is what we're seeing here. However, if the argument type is an un-bound variable, BSC should probably report the error differently.

I notice, for example, that I can't cause the same issue with array assignment (with [] and =):

module mkTest();
  rule rl;
    Reg#(Bool) b;
    b[0] = True;
  endrule
endmodule

That gives the error message:

Error: "Test2.bsv", line 4, column 6: (T0095)
  Compile-time updates with [] and = are not defined for the type:
    Reg#(Bool)

Metadata

Metadata

Assignees

No one assigned

    Labels

    error-messagesImprovements to user messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions