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

Compile checks for constants do not work #17

Open
egroge opened this issue Sep 7, 2020 · 0 comments
Open

Compile checks for constants do not work #17

egroge opened this issue Sep 7, 2020 · 0 comments
Labels
bug Something isn't working language Issues with the flint-2 Flint language implementation or features semantic check Problems with the semantic analysis stage

Comments

@egroge
Copy link
Collaborator

egroge commented Sep 7, 2020

Semantic analysis does not successfully test for reassignments to constants. At the moment, some limited checking exists. For example, the following contract would not compile:

contract A {
  let a: Int = 0
}

A :: (any) {
  public init() {
    self.a = 5 // Error
  }
}

However, note that if self.a = 5 were instead a = 5, then the error would not be caught.
This kind of check also works for local variables, such as the following example, were it part of a top level declaration:

public func foo() {
  let my_const: Int = 0
  my_const = 1 // Error
}

However, there are cases where the checker allows reassignments through when it should not, such as:

contract A {
  let a: Int
}

A :: (any) {
  public init() {
    a = 0
  }

  public func foo() mutates(a) {
    a = 1 // or self.a = 1
  }
}
@egroge egroge added bug Something isn't working language Issues with the flint-2 Flint language implementation or features semantic check Problems with the semantic analysis stage labels Sep 7, 2020
@egroge egroge changed the title Compile checks for reassignments to constants do not work Compile checks for constants do not work Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working language Issues with the flint-2 Flint language implementation or features semantic check Problems with the semantic analysis stage
Projects
None yet
Development

No branches or pull requests

1 participant