Skip to content

Commit

Permalink
Fixed a dynamic state test bug: only reset the tested variable's type…
Browse files Browse the repository at this point in the history
… if it is still in scope.
  • Loading branch information
mcoblenz committed Nov 27, 2019
1 parent 6025ed6 commit 1a09352
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
21 changes: 20 additions & 1 deletion resources/tests/type_checker_tests/InState.obs
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,23 @@ contract TestFieldShared {
->S1(next = temp);
}
}
}
}

contract TestTransition {
state S1;
state S2 {
TestTransition@Shared x;
}

TestTransition@S1() {
->S1;
}

transaction t1(TestTransition@Shared this) {
if (this in S2) {
if (x in S2) {
->S1;
}
}
}
}
16 changes: 13 additions & 3 deletions src/main/scala/edu/cmu/cs/obsidian/typecheck/Checker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ class Checker(globalTable: SymbolTable, verbose: Boolean = false) {
}
}

// Removes any field types from thisFieldTypes that are already consisten with their declarations.
// Removes any field types from thisFieldTypes that are already consistent with their declarations.
private def packFieldTypes(context: Context): Context = {
var resultContext = context
for ((field, typ) <- context.thisFieldTypes) {
Expand Down Expand Up @@ -1986,8 +1986,18 @@ class Checker(globalTable: SymbolTable, verbose: Boolean = false) {
case None => (packedTrueContext, packedFalseContext)
case Some((x, oldType)) =>
if (exprIsField) {
(packedTrueContext.updatedThisFieldType(x, oldType),
packedFalseContext.updatedThisFieldType(x, oldType))
// Only reset the tested field in the context if it is still in scope (since the type of this may have changed)
val revisedTrueContext = if (packedTrueContext.lookupDeclaredFieldTypeInThis(x).isDefined) {
packedTrueContext.updatedThisFieldType(x, oldType)
} else {
packedTrueContext
}
val revisedFalseContext = if (packedFalseContext.lookupDeclaredFieldTypeInThis(x).isDefined) {
packedFalseContext.updatedThisFieldType(x, oldType)
} else {
packedFalseContext
}
(revisedTrueContext, revisedFalseContext)
}
else {
(packedTrueContext.updated(x, oldType), packedFalseContext.updated(x, oldType))
Expand Down

0 comments on commit 1a09352

Please sign in to comment.