[SUGGESTION] Independent order and type data members #641
Replies: 4 comments
-
There's also no order independence in a type's Cpp1 declaration (template parameters and requires clause).
|
Beta Was this translation helpful? Give feedback.
-
Here is the order of emitted Cpp1
That results in these order dependencies:
|
Beta Was this translation helpful? Give feedback.
-
See the last paragraph of #75 (comment). |
Beta Was this translation helpful? Give feedback.
-
@hsutter What do you think about Right now, a |
Beta Was this translation helpful? Give feedback.
-
Independent order of declaration works for functions, because definitions of those functions put after declarations of variables.
However, declarations of types can intertwine with variables, so data members not always can refer those globals.
Code Example
S: type = {
mi: int = i; //cpp1 error - undeclared i
pi: * int = i&; //cpp1 error - undeclared i
f: () = std::cout << i; //ok, function definition pushed down
}
main: () = {
li:= i; //ok, function definition pushed down
std::cout << i; //ok
}
i: int = 42;
Additional note
Probably hard to solve, requiring some sort of dependency graph
Namespaces doesn't seem to help here, because namespace itself still may be placed after class declaration.
In this case workaround is simple - move
i: int = 42;
declaration beforeS
declarationBeta Was this translation helpful? Give feedback.
All reactions