Skip to content

Static initialization should use static initializer #8

Description

@zeen

Given code like

static var x = 5;

we get code like this:

static int x;
+ (int) x {
    if (x == nil) x = 50;
    return x;
}

This breaks badly for non-Dynamic types. Even for Dynamic types, it becomes impossible to set such a variable to null later on in the code, because on next access, it's reinitialized again. So these assignments should be done in a static initializer (#7).

Also, lack on an initialization value leads to bad code:

static var x;

leads to:

static int x;
+ (int) x {
    if (x == nil) x = ; // <-- invalid code
    return x;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions