         " in #{ctx.definitionName()}"
       else
         ""
-    compiledCases = conditional (for [pattern, result] in pairs cases
-
+
+    # mark all used as used (remember them)
+    oldUsed = ctx.usedNames()
+    compiledResults = (for [pattern, result] in pairs cases
+      ctx.setUsedNames []
       ctx.newScope() # for variables defined inside pattern
       ctx.defineNonDeferrablePattern pattern
       {precs, assigns} = patternCompile ctx, pattern, subject, no

      ctx.resetAssignTo()
      ctx.leaveDefinition()
      ctx.closeScope()

      if ctx.shouldDefer()
        continue

      # TODO: we need to check that
      # log "unifying in match", result, resultType, result.tea
      unify ctx, resultType, result.tea.type
      constraints.push result.tea.constraints...
      varNames.push (findDeclarables precs)...

      matchBranchTranslate precs, assigns, compiledResult
    ), "throw new Error('match failed to match#{errorMessage}');" #TODO: what subject?
    translationCache = ctx.resetAssignTo()
    call.tea = new Constrained constraints, resultType
    assignCompile ctx, call, iife concat (filter _is, [

      varList varNames
      compiledCases])

# Creates the condition and body of a branch inside match macro
matchBranchTranslate = (precs, assigns, compiledResult) ->
  {conds, preassigns} = constructCond precs
  # [hoistedWheres, furtherHoistable] = hoistWheres [], assigns #hoistWheres hoistableWheres, assigns

  [conds, concat [
    (map compileVariableAssignment, (join preassigns, assigns))
