Opened 12 months ago

Last modified 12 months ago

#185 new defect

Cannot declare generic struct with zero type parameters

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

Change History (1)

comment:1 Changed 12 months ago by mlbrooks

Priority: majorminor

Fixing status; should have been opened as minor.

Note: See TracTickets for help on using tickets.