From 23469e1e2233c7ee26ee1436b620fb3c9ecf273d Mon Sep 17 00:00:00 2001
From: "Emmanouil (Manos) Koukoutos" <emmanouil.koukoutos@epfl.ch>
Date: Thu, 20 Nov 2014 17:16:16 +0100
Subject: [PATCH] Don't eliminate pattern matching if
 scrutinee:AbstractClassType

---
 src/main/scala/leon/purescala/SimplifierWithPaths.scala  | 3 ++-
 .../regression/transformations/SimplifyPaths.scala       | 9 +++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/main/scala/leon/purescala/SimplifierWithPaths.scala b/src/main/scala/leon/purescala/SimplifierWithPaths.scala
index 481cee54b..6353c6d90 100644
--- a/src/main/scala/leon/purescala/SimplifierWithPaths.scala
+++ b/src/main/scala/leon/purescala/SimplifierWithPaths.scala
@@ -113,7 +113,8 @@ class SimplifierWithPaths(sf: SolverFactory[Solver]) extends TransformerWithPC {
       }
       newCases match {
         case List() => Error("Unreachable code").copiedFrom(e)
-        case List(theCase) => 
+        case List(theCase) if !scrut.getType.isInstanceOf[AbstractClassType] => 
+          // Avoid AbstractClassType as it may lead to invalid field accesses
           replaceFromIDs(mapForPattern(scrut, theCase.pattern), theCase.rhs)
         case _ => MatchExpr(rs, newCases).copiedFrom(e)
       }
diff --git a/src/test/resources/regression/transformations/SimplifyPaths.scala b/src/test/resources/regression/transformations/SimplifyPaths.scala
index 245e06f94..792b6d4a2 100644
--- a/src/test/resources/regression/transformations/SimplifyPaths.scala
+++ b/src/test/resources/regression/transformations/SimplifyPaths.scala
@@ -81,4 +81,13 @@ object Transform {
       a._1
     }
 
+    def input07(l : List[Int]) : Int = l match {
+      case Nil() if false => 42
+      case Cons(h,t) => h
+    }
+
+    def output07(l : List[Int]) : Int = l match {
+      case Cons(h,t) => h
+    }
+
 }
-- 
GitLab