kphp icon indicating copy to clipboard operation
kphp copied to clipboard

The problem of cyclic dependency with inheritance

Open mkornaukhov03 opened this issue 1 year ago • 0 comments

Assume we have the following class hierarchy: image There is a a possible situation when such a hierarchy cannot be compiled. For example, if in any C++ Translation Unit inclusion of "С-class.h" or "D-class.h" will precede all other class headers of this hierarchy. The reason is in mechanism of header inclusion in KPHP.

A possible solution is following:

  1. To stop include class definition headers for properties and use only incomplete declarations.
  2. Include full class definitions for functions that uses such properties

Or we could just detect such situations and give human-readable error; for now it's g++ stage error:

...
error: expected class-name before ‘{’ token:
struct C$D: public C$D {
...

But, as I believe, the solution or detection would require analysis, which would take considerable time..

mkornaukhov03 avatar May 29 '23 12:05 mkornaukhov03