Opened 5 years ago
Last modified 4 months ago
#185 new defect
Cannot declare generic struct with zero type parameters — at Initial Version
| Reported by: | mlbrooks | Owned by: | |
|---|---|---|---|
| Priority: | minor | Component: | cfa-cc |
| Version: | 1.0 | Keywords: | |
| Cc: |
Description
Wishing for:
forall ( | {void fun();} ) {
struct thing {};
void ?{}( thing & this ) {
fun();
}
}
void fun() {
printf("this is fun\n");
}
int main() {
thing x;
}
That is, the forall is used only to declare an assertion.
Expect: compile succeeds; run prints
this is fun
Actual: compiler error
Too few type arguments in generic type instance of struct thing with body 1
Workaround is to treat the generic type as if it had one type parameter, i.e.
forall ( dtype T | {void fun();} ) {
struct thing ...
This workaround is
forall ( | {void fun();} ) {
struct thing {};
void ?{}( thing(float) & this ) {
fun();
}
}
void fun() {
printf("this is fun\n");
}
int main() {
thing(float) x;
}
Workaround Expected: compiler error
Too many type arguments in generic type instance of struct thing...
Workaround Actual: compile succeeds; run prints
this is fun
Note:
See TracTickets
for help on using tickets.