18944, "jhh67", "improve error messages when accessing a field of a class instance", "2022-01-07T21:50:38Z"
When trying to compile
class Node {
var count: int = 0; // # of nodes in the subtree
var left: shared Node? = nil;
var right: shared Node? = nil;
}
var root: Node? = new Node();
root.left = nil;
I get the following error messages
bar.chpl:1: In module 'bar':
bar.chpl:10: error: unresolved call 'owned Node?.left'
bar.chpl:4: note: this candidate did not match: left this: borrowed Node [874061]
bar.chpl:10: note: because method call receiver with type 'owned Node?'
bar.chpl:4: note: is passed to formal 'this: borrowed Node [874065]'
bar.chpl:10: note: try to apply the postfix ! operator to method call receiver
There are references to an "unresolved call" and a "method call", even though the code doesn't invoke a method. Also
bar.chpl:4: note: this candidate did not match: left this: borrowed Node [874061]
seems to indicate that the left
field is of type borrowed Node
but its type is shared Node?
. I don't know if this is a bug in the error message or it is revealing something subtle about the type of the field left
, but either way it's confusing.