Opened 4 weeks ago
#315 new defect
Peculiar trait syntax neither rejected nor supported
| Reported by: | mlbrooks | Owned by: | |
|---|---|---|---|
| Priority: | minor | Component: | cfa-cc |
| Version: | 1.0 | Keywords: | trait syntax |
| Cc: |
Description
Consider this basic, working, program with a trait.
forall( T & )
trait has_global {
T * global;
};
forall( T & | has_global(T) )
void f( T & parm ) {
printf("f: global @ %p; parm @ %p\n", global, & parm );
}
int main() {
float x;
float * global = & x;
f(x);
}
Actual and expected: output like:
f: global @ 0x7fffffffde88; parm @ 0x7fffffffde88
Now suppose the programmer instead made this mistake, or curious choice:
forall( T & | { T * global; } )
trait has_global {};
Actual: error: duplicate object definition for global: pointer to instance of type T (not function type)
Expected: one of:
- error like: a trait's forall cannot introduce bare assertions, put new declarations in the trait's body, or
- same as working version
This mistake came up naturally, when trying to refactor a more complex trait, turning
forall( T & | IS_RESUMPTION_EXCEPTION(CoroutineCancelled(T)) )
trait is_coroutine {
void main(T & this);
coroutine$ * get_coroutine(T & this);
};
forall( T & | is_coroutine(T) | { EHM_DEFAULT_VTABLE(CoroutineCancelled(T)); } )
void prime(T & cor);
into
forall( T & | IS_RESUMPTION_EXCEPTION(CoroutineCancelled(T)) )
trait is_coroutine {
void main(T & this);
coroutine$ * get_coroutine(T & this);
EHM_DEFAULT_VTABLE(CoroutineCancelled(T));
};
forall( T & | is_coroutine(T) )
void prime(T & cor);
but mistakenly giving
forall( T & | IS_RESUMPTION_EXCEPTION(CoroutineCancelled(T)) | { EHM_DEFAULT_VTABLE(CoroutineCancelled(T)); } )
trait is_coroutine {
void main(T & this);
coroutine$ * get_coroutine(T & this);
};
Note:
See TracTickets
for help on using tickets.