Skip to content
  • Simon Peyton Jones's avatar
    Care with impossible-cons in combineIdenticalAlts · 023a0ba9
    Simon Peyton Jones authored
    This was a nasty, long-standing bug exposed in Trac #10538.
    Symptoms were that we had an empty case
       case (x :: Either a) of {}
    Core Lint correctly picked this bogus code up.
    
    Here is what happened
    
    * In SimplUtils.prepareAlts, we call
            filterAlts
      then
            combineIdenticalAlts
    
    * We had    case x of { Left _ -> e1; Right _ -> e1 }
    
    * filterAlts did nothing, but correctly retuned imposs_deflt_cons
      saying that 'x' cannot be {Left, Right} in the DEFAULT branch,
      if any (there isn't one.)
    
    * combineIdentialAlts correctly combines the identical alts, to give
         case x of { DEFAULT -> e1 }
    
    * BUT combineIdenticalAlts did no adjust imposs_deft_cons
    
    * Result: when compiling e1 we did so in the belief that 'x'
      could not be {Left,Right}.  Disaster.
    
    Easily fixed.
    
    (It is hard to trigger; I can't construct a simple test case.)
    023a0ba9