16984, “dlongnecke-cray”, “Strange behavior in record init when defining a proc= overload as a primary method”, “2021-01-22T00:17:29Z”
Summary of Problem
When writing a test, I accidentally defined a proc=
overload as a primary method of a record, instead of as a freestanding function. This caused the record’s copy init method to issue strange errors referencing this.complete()
.
This code works fine if the proc=
method is removed or is turned into a function.
Steps to Reproduce
Source Code:
record r {
var c: int;
proc init() {
this.complete();
}
proc init(other: r) {
this.c = other.c; // <-- Error is: "cannot call a method on a record before this.complete()"
this.complete();
}
proc =(ref lhs: r, const ref rhs: r) {}
}
Test Output:
Test.chpl:8: In initializer:
Test.chpl:9: error: cannot call a method on a record before this.complete()
Test.chpl:9: error: field "c" used before it is initialized