In response to the problem you see in the EDIT example:
I am afraid that you will find yourself in the dark corner of the compiler from version 1.17, and I am sorry that it exists, although I think we can get you out of it.
Starting from some background and important context: from the very beginning, Chapel supported class and record constructors (e.g. proc C(...) for class C ), but they were naive in design, in particular wrt common classes and records. Over the past few releases, we have moved from constructors to initializers (such as proc init(..) for class C ) to remove these limitations.
To date, version 1.17, initializers are in pretty good shape (for example, now I use them for all the new code that I write, and rarely swear at them), but if you did not provide either an initializer or a constructor (as in your examples ), the compiler will create a default constructor (rather than a default initializer) and thus may encounter some of these long-standing problems. For version 1.18, the goal is for the compiler to create default initializers and completely condemn constructors.
So, here are some ways to get around the problem for your smaller test program in EDIT, all of which seem to give the correct result for me in version 1.17 of Chapel:
1) Make the class less general. Here I gave the dom field an initial value, so that the compiler can determine its type, and this seems to help it with the default constructor, sufficient to generate the expected result:
class Test { var dom = {0..-1}; var ints: [dom] int; proc resize(size) { dom = {dom.low..size}; } } var test = new Test(dom = {0..-1}); writeln(test); test.resize(1); writeln(test);
2) Write an explicit initializer. Here I leave dom generic, but create an initializer that assigns it to match the signature of your new call:
class Test { var dom; var ints: [dom] int; proc init(dom: domain(1)) { this.dom = dom; } proc resize(size) { dom = {dom.low..size}; } } var test = new Test(dom = {0..-1}); writeln(test); test.resize(1); writeln(test);
3) (last resort) Request the compiler to create a default initializer (and not a standard constructor) for you. This approach is really not intended for end users, it will not work for all cases and will go away in the future, but it may be convenient to know about it. Here I am attaching a pragma to the class to tell the compiler to create a default initializer, and not a default constructor. Although the default compiler does not create default initializers, for many classes and records, it can, if you ask, and this is one of them:
pragma "use default init" class Test { var dom; var ints: [dom] int; proc resize(size) { dom = {dom.low..size}; } } var test = new Test(dom = {0..-1}); writeln(test); test.resize(1); writeln(test);
In the interests of space, I considered only your shorter example, and not your longer one, but I hope that these methods will also help with it (and I will gladly spend more time on a longer one, if necessary).