You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
given that static initialization is handled "out of band", there are subtle dependency relationships that currently aren't being fully upheld (currently the compiler will detect dependency errors more aggressively than is needed):
class Foo
{
// non-static (pre-ctor) code that calls a static function
bar();
// static data (needed by static function)
5 => static float foo;
// static function
fun static float bar() { return foo; }
}
<<< Foo.foo >>>;
This currently fails compilation with the dependency error (but is actually valid code, due to static initialization happening at compile-time)
c.ck:4:5: error: calling 'bar()' at this point skips initialization of a needed variable:
[4] bar();
^
c.ck:7:23: error: ...(note: this skipped variable initialization is needed by 'fun float Foo.bar()')
[7] 5 => static float foo;
^
c.ck:9:37: error: ...(note: this is where the variable is used within 'fun float Foo.bar()' or its subsidiaries)
[9] fun static float bar() { return foo; }
^
c.ck: ...(hint: try calling 'bar()' after the variable initialization)
however, there is more complexity to consider in addressing the above -- while a static function cannot directly access instance data, it can implicitly depend on instance data, for example through the use of new:
public class Bar
{
// instance data
int var;
// a static function that returns a new instance of Bar -- this is valid btw
fun static Bar make() { return new Bar(); }
}
class Bar
{
// this implicitly uses Bar.name...
// also would cause a infinite loop, but won't get that far
BarFactory.make();
// the var
"i am bar" => string name;
}
class BarChild extends Bar
{
"success" => name;
}
class BarFactory
{
fun static BarChild make()
{
return new BarChild;
}
}
// shouldn't quite get to here
BarFactory.make();
The text was updated successfully, but these errors were encountered:
given that static initialization is handled "out of band", there are subtle dependency relationships that currently aren't being fully upheld (currently the compiler will detect dependency errors more aggressively than is needed):
This currently fails compilation with the dependency error (but is actually valid code, due to static initialization happening at compile-time)
however, there is more complexity to consider in addressing the above -- while a static function cannot directly access instance data, it can implicitly depend on instance data, for example through the use of
new
:Things get extra complicated with inheritance, as seen in unit test error-depend-class-extend.ck
The text was updated successfully, but these errors were encountered: