Skip to content

Commit

Permalink
Keep track of fields that were initialized with S::x = e in construct…
Browse files Browse the repository at this point in the history
…ors to avoid giving spurious uninitialized field errors.
  • Loading branch information
mcoblenz committed Dec 4, 2019
1 parent abf02c3 commit 1c23080
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions resources/tests/type_checker_tests/StateInitialization.obs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,14 @@ main asset contract Wallet {
->S1(m = new Money()); // Error: double initialization
}
}

contract HasField {
int x;

state S{}

HasField@Owned() {
S::x = 2;
->S;
}
}
3 changes: 3 additions & 0 deletions src/main/scala/edu/cmu/cs/obsidian/typecheck/Checker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,9 @@ class Checker(globalTable: SymbolTable, verbose: Boolean = false) {
contextAfterTransition = contextAfterTransition.updatedWithFieldInitialization(update._1.name)
}
}
for (assignmentUpdate <- updatedViaAssignment) {
contextAfterTransition = contextAfterTransition.updatedWithFieldInitialization(assignmentUpdate)
}

(contextAfterTransition, Transition(newStateName, newUpdatesOption, context.thisType.permission).setLoc(s))

Expand Down

0 comments on commit 1c23080

Please sign in to comment.