diff --git a/source/tlang/compiler/typecheck/dependancy.d b/source/tlang/compiler/typecheck/dependancy.d index 6dac1f8f..c29f6b79 100644 --- a/source/tlang/compiler/typecheck/dependancy.d +++ b/source/tlang/compiler/typecheck/dependancy.d @@ -71,7 +71,17 @@ public void dependancyGenerate(TypeChecker tc, Container container) if(container == tc.getModule()) { /** - * If it is a variable + * If we have a module-level variable declaration then we want to check + * if the type of the variable being declared is: + * + * 1. Basic (int, float, etc.) + * - Then we will do nothing, it is not dependent + * 2. Non-basic (Class-case only) + * - Then we will check if that class is accessible + * 1. If it is at the module-level then it is implied static so it would be + * 2. If at a level deeper then more care must be taken + * + * TODO: Assignments still not supported as this means more checking */ if(cast(Variable)entity) { @@ -81,19 +91,31 @@ public void dependancyGenerate(TypeChecker tc, Container container) Type variableType = tc.getType(container, variable.getType()); /** - * TODO: Here we must decide, if it is basic type then no init -> no dependence - * The only depenedence would be what comes next (a.k.a. if an assignment exists) - * then dependence from the expression must be checked - * - * Non-basic types that have static initiliazation on type reference: Class + * Check if the type is a class type */ if(cast(Clazz)variableType) { - /** - * Mark the variable as dependent on the class type (`variableType`) having - * been statically initialized - */ - encounter(tc, variable, variableType); + Clazz classType = cast(Clazz)variableType; + + /* If the class is defined at the module-level then it is static by default */ + if(classType.parentOf() == tc.getModule()) + { + /** + * Then mark the class as a dependency (the class-name/type reference) + * must cause the static initialization to go off + * + * module pp; + * Person k; + * class Person { } + * + * Above it means that because the type of `k` is `Person` and that is a + * class type therefore the Person class should have its static constructor + * run (=> all static members should be initialized) + */ + encounter(tc, variable, classType); + } + + } /* If then variable has an assignment */