27411, "bradcray", "Duplicate fully generic 'myType(?)' fields result in compiler errors", "2025-06-19T00:07:13Z"
As reported in Unable to compile `pure virtual method called`, it seems that when multiple fields have a completely generic type, the compiler generates errors of various kinds depending on the details of the code and the compiler invocation. For example:
class C {
var d: domain(?);
var d2: domain(?);
proc init() {
this.d = {1..10};
this.d2 = {1..20};
}
}
var c = new C();
writeln(c);
gives me:
error: could not find C type for _unknown_chpl
with Chapel 2.5, whereas
record R {
type t;
var x: t;
}
record S {
var x: R(?);
var y: R(?);
proc init() {
this.x = new R(int);
this.y = new R(int);
}
}
var myS = new S();
writeln(myS);
gives:
testit.chpl:8: In method 'y':
testit.chpl:8: error: unable to resolve type
testit.chpl:6: called as (S(R(int(64)))).y
within internal functions (use --print-callstack-on-error to see)
note: generic instantiations are underlined in the above callstack
When the fields have the same type, a workaround is to have them share the type declaration, like:
class C {
var d, d2: domain(?);
proc init() {
this.d = {1..10};
this.d2 = {1..20};
}
}
in the first case, or
record S {
var x, y: R(?);
proc init() {
this.x = new R(int);
this.y = new R(int);
}
}
in the second. Another workaround that handles the case when the types are different is simply to have the field types after the first be inferred completely, using:
class C {
var d: domain(?);
var d2;
proc init() {
this.d = {1..10};
this.d2 = {1..20};
}
}
or:
record S {
var x: R(?);
var y;
proc init() {
this.x = new R(int);
this.y = new R(int);
}
}
I suspect that these solutions suggest that our handling of myType(?) fields is incorrect or getting confused in some way.