Open lydia-duncan opened 2 years ago
To me, this feels more like an "error message" issue than a "bug" issue in that only variables/fields of nothing
type can store none
values in Chapel, so it seems appropriate that you couldn't store none
into that field. That said, the error message doesn't make this very clear, which is why I'd expect the issue to be to improve the error message.
I agree. I think instead of
record Foo {
var funcStored = false;
var funcField: func(int, bool) = none;
...
}
you would need to write
record Foo {
type funcType; // an FCF type or 'nothing'
var funcField: funcType;
proc init(x: func(int, bool)) {
funcType = func(int, bool);
funcField = x;
}
proc init() {
funcType = nothing;
funcField = none;
}
...
}
Ah, I see my confusion. I suspect part of this comes from a misunderstanding of the nothing
type/none
value due to not using it extensively myself and purely hearing its description. My understanding was that it would allow a field to be optimized out but that its original type was important and something that should be specified somewhere, and the obvious place to me was on the field itself. I'll update the test I filed with this information and play around with it more, thanks!
Thinking about this from a documentation perspective, I think this argues that initializers should be part of a (or at least this) type's documentation, so that a user of the type can know exactly what interface the fcf is expected to have. I also wonder if it would have helped me to have a commented out code example in the nothing
primer that explicitly called out you can't give a field an explicit type if you wish it to be able to have none
as a value.
Summary of Problem
I tried making a field that stores a first class function use the
nothing
type and the compiler was unhappy. It outputs the following:Edit: this error message was unhelpful, but it turns out I should have declared the field type when trying to do this. I suspect this is a more general problem than fcfs.
The details block has the actual scenario that motivated me to find this, for the curious:
Steps to Reproduce
Source Code:
Compile command:
chpl foo.chpl
Execution command: N/A
Associated Future Test(s):
test/functions/firstClassFns/saveInField-nothing.chpl
#20176Configuration Information
chpl --version
: 1.28.0 (pre-release)