A class with a type method that returns a type that depends on a type or param argument of the method, results in an error (shown below).
Source Code:
class Sandwich {
type eltType; // Same thing occurs if this is a 'param' instead
proc type make(type t): Sandwich(t) {
return new Sandwich(t);
}
}
var realSandwich = Sandwich.make(real);
Compile output:
sandwich.chpl:10: error: unresolved type specifier 'Sandwich()'
sandwich.chpl:1: note: candidates are: Sandwich(type eltType)
Associated Future Test(s):
TODO
chpl --version: chpl Version 1.16.0 pre-release (a110861)@noakesmichael was interested in this - hope I didn't butcher this issue title too bad.
Context: This came up when discussing alternatives to the QueueFactory class in #6812 with @LouisJenkinsCS
I think this has to do with calling a type method on a generic
class. not with what the type method returns or depends on.
I get the same error with this:
class Sandwich {
var filling;
proc type eat() {
writeln("Mmm");
}
}
Sandwich.eat();
But it works with the last line changed to
Sandwich(string).eat();
And conversely, a non-generic class with a type method that
returns a type that depends on a type argument of the method
works:
```chapel
class Soup {
type eltType;
}
class Sandwich {
proc type make(type t) {
writeln("Out of sandwiches. Have some ", t:string, " soup!");
return new Soup(t);
}
}
var s = Sandwich.make(string);
writeln(s);
delete s;
I don't know what the QueueFactory was going to look like, but I
modified my last example and sudo made you a sandwich factory,
which works for me:
class Sandwich {
type eltType;
}
class SandwichFactory {
proc type make(type t) {
return new Sandwich(t);
}
}
var s = SandwichFactory.make(string);
writeln(s.type:string);
delete s;
Is this not-a-bug?
Doesn't seem like it, does it? @ben-albrecht?
Agreed. Thank you for @cassella