Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code actions for isolated constructs #28681

Open
MaryamZi opened this issue Feb 16, 2021 · 1 comment
Open

Code actions for isolated constructs #28681

MaryamZi opened this issue Feb 16, 2021 · 1 comment
Assignees
Labels
Area/CodeAction Language Server Code Actions Team/LanguageServer Language Server Implementation related issues. #Compiler Type/Improvement

Comments

@MaryamZi
Copy link
Member

Description:
Few suggestions for potential code actions for isolated constructs,

  • A non-final isolated variable can only be accessed within a lock statement.
isolated int i = 1;

function increment() {
    i += 1;
}

This fails with invalid access of an 'isolated' variable outside a 'lock' statement, and can be fixed using a lock statement. Can we provide a code action to do the same?

isolated int i = 1;

function increment() {
    lock {
        i += 1;
    }
}

This is also the case for accessing self in an isolated class.

isolated class Foo {
    private int i = 1;

    function increment() {
        self.i += 1; // error: invalid access of a mutable field of an 'isolated' object outside a 'lock' statement
    }
}
  • A field in an isolated class that is not final and/or does not have a type that is a subtype of readonly needs to be private.
isolated class Foo {
    int i = 1; // invalid non-private mutable field in an 'isolated' object
}

can be fixed by making it a private field.

isolated class Foo {
    private int i = 1;
}
  • An isolated function can access variables defined outside the function only if it is either an isolated variable or if it is a variable that is both final and has a subtype of readonly.

Can we provide a code action for at least marking a variable as an isolated variable?

int[] arr = [];

isolated function length() returns int {
    return arr.length();
}

Can be fixed either by doing

isolated int[] arr = [];

isolated function length() returns int {
    lock {
        return arr.length();
    }
}

or

final int[] & readonly arr = [];

isolated function length() returns int {
    return arr.length();
}

Affected Versions:
slalpha2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/CodeAction Language Server Code Actions Team/LanguageServer Language Server Implementation related issues. #Compiler Type/Improvement
Projects
Status: BackLog
Development

No branches or pull requests

4 participants