Skip to content

Commit

Permalink
Merge pull request #162 from marcoeilers/fix_161
Browse files Browse the repository at this point in the history
Correctly tracking assignments to static fields
  • Loading branch information
marcoeilers authored Jan 20, 2024
2 parents b947185 + b5126ed commit 03c1bca
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/nagini_translation/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ def todo():
# (non-static) field, and created the field. We remove it
# again now that we now it's actually static.
del self.current_class.fields[node.id]
self.track_access(node, var)
return
# We're in a function
if isinstance(node.ctx, ast.Store):
Expand Down
2 changes: 2 additions & 0 deletions src/nagini_translation/translators/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,8 @@ def _assign_single_value(self, lhs: ast.AST, rhs: Expr, rhs_type: PythonType,
after_assign = []
if isinstance(target, PythonGlobalVar):
if target.is_final:
if lhs not in target.writes:
raise UnsupportedException(lhs, "Internal error: Variable may have been incorrectly tagged as final.")
# For final variables, we assume that the function representing the
# variable is equal to the RHS of the assignment. For pure values,
# this will do nothing, since the postcondition will already say the same;
Expand Down
23 changes: 23 additions & 0 deletions tests/functional/verification/issues/00161.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/

from nagini_contracts.contracts import *

class Parent:
x = 100


class Subclass:
y = 200

def __init__(self) -> None:
self.x = 100
Ensures(Acc(self.x))


def main() -> None:
instance = Subclass()
#:: ExpectedOutput(assert.failed:insufficient.permission)
Assert(instance.y == 200)
Subclass.y = 300
Assert(instance.y == 200)

0 comments on commit 03c1bca

Please sign in to comment.