Skip to content

Commit

Permalink
Fixed bugs in the type checker for switch: test for exiting in a way …
Browse files Browse the repository at this point in the history
…that includes revert,

and when merging with initial branches that exit, pass the appropriate flag to the merging code.
  • Loading branch information
mcoblenz committed May 5, 2020
1 parent 1cb8291 commit 0bff4e6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/scala/edu/cmu/cs/obsidian/typecheck/Checker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2180,13 +2180,18 @@ class Checker(globalTable: SymbolTable, verbose: Boolean = false) {
// If a given switch case is guaranteed to return, then if it DID run, then the code BELOW this will NEVER run, so
// we need not merge the case's output context in.
val (firstCaseOutputContext, newCase) = checkSwitchCase(switchCase)
val firstCaseExits = hasReturnStatementDontLog(switchCase.body) || firstCaseOutputContext.isThrown

val initialContextToMerge = if (hasReturnStatementDontLog(switchCase.body)) contextPrime else firstCaseOutputContext

var foundNonExitingCaseYet = !firstCaseExits
val initialContextToMerge = if (firstCaseExits) contextPrime else firstCaseOutputContext
val restCases = cases.tail
restCases.foldLeft((initialContextToMerge, Seq(newCase)))((prev: (Context, Seq[SwitchCase]), sc: SwitchCase) => {
val (newContext, newCase) = checkSwitchCase(sc)
val caseExits = hasReturnStatementDontLog(sc.body) || newContext.isThrown
(mergeContext(s, prev._1, newContext, false, caseExits), newCase +: prev._2)
val res = (mergeContext(s, prev._1, newContext, !foundNonExitingCaseYet, caseExits), newCase +: prev._2)
foundNonExitingCaseYet = foundNonExitingCaseYet || caseExits
res
})
}

Expand Down

0 comments on commit 0bff4e6

Please sign in to comment.