diff --git a/src/Checks/TypeClassesCheck.hs b/src/Checks/TypeClassesCheck.hs
index dd7037fcc65a0cbf5b5367949bd1e5562519b2b0..203deb55b0bc9b6af2a805edf5579527f20097e7 100644
--- a/src/Checks/TypeClassesCheck.hs
+++ b/src/Checks/TypeClassesCheck.hs
@@ -760,13 +760,13 @@ checkForInstanceDataTypeExistAlsoInstancesForSuperclasses _ _ _ _
 -- |returns the instance from the class environment for the given instance
 -- declaration. This function must be called only after it has been checked
 -- that as well the class name and the type name are valid (i.e., in phase 3)
-getInstance' :: ModuleIdent -> ClassEnv -> TCEnv -> Decl -> Instance
+getInstance' :: ModuleIdent -> ClassEnv -> TCEnv -> Decl -> Maybe Instance
 getInstance' m cEnv tcEnv (InstanceDecl _p (SContext _scon) cls ty _tyvars _) =
   inst 
   where 
   tyId = fromJust $ tyConToQualIdent m tcEnv ty
   cls' = getCanonClassName m cEnv cls
-  inst = fromJust $ getInstance cEnv cls' tyId
+  inst = getInstanceWithOrigin cEnv m cls' tyId
 getInstance' _ _ _ _ = internalError "getInstance'"
 
 -- |Returns a Base.Types.Context for the given instance. The type
@@ -795,7 +795,8 @@ checkInstanceContextImpliesAllInstanceContextsOfSuperClasses ::
     ClassEnv -> TCEnv -> ModuleIdent -> Decl -> Tcc ()
 checkInstanceContextImpliesAllInstanceContextsOfSuperClasses cEnv tcEnv m
     inst@(InstanceDecl p _scon cls ty _tyvars _)
-  = let inst' = getInstance' m cEnv tcEnv inst
+  = let inst0 = getInstance' m cEnv tcEnv inst
+        inst' = fromJust inst0
         thisContext = getContextFromInst inst'
         scs = allSuperClasses cEnv (getCanonClassName m cEnv cls)
         tyId = tyConToQualIdent m tcEnv ty
@@ -810,8 +811,9 @@ checkInstanceContextImpliesAllInstanceContextsOfSuperClasses cEnv tcEnv m
         instCxs' = getSContextFromContext instCxs (typeVars inst')
         notImplCxs = (filter (not . implies cEnv thisContext) instCxs)
         notImplCxs' = getSContextFromContext notImplCxs (typeVars inst') in
-    when (isJust tyId) $ unless (implies' cEnv thisContext instCxs) $ report $  
-      errContextNotImplied p thisContext' instCxs' notImplCxs'
+    -- catch the case that there are duplicate local instances
+    when (isJust tyId && isJust inst0) $ unless (implies' cEnv thisContext instCxs) $ 
+      report $ errContextNotImplied p thisContext' instCxs' notImplCxs'
         
 checkInstanceContextImpliesAllInstanceContextsOfSuperClasses _ _ _ _
   = internalError "checkInstanceContextImpliesAllInstanceContextsOfSuperClasses"
diff --git a/test/test2.sh b/test/test2.sh
index 91c57fea48d671b35d7a8cb1e033655d51debc5f..752f03d9acae9a0ae71b8f8612a5bc09b14efd3a 100644
--- a/test/test2.sh
+++ b/test/test2.sh
@@ -62,7 +62,8 @@ for file in checkCorrectTypeVarsInTypeSigs CheckRulesInClass CheckRulesInInstanc
   ContextImplication ContextsInClassMethodTypeSigs Cycles directCycle \
   doubleClassMethods duplicateClassNames duplicateInstances InstanceConstraints \
   instanceDataTypeCorrect InstanceTypeVarsDoNotAppearTwice SuperclassInstances \
-  typeVarsInInstContext typeVarsInTySigContext TyVarInContext AmbiguousInstancesUse
+  typeVarsInInstContext typeVarsInTySigContext TyVarInContext AmbiguousInstancesUse \
+  DuplicateInstances2
 do
   echo $file >> tmp.txt
   if [ ! -r typeclasses/TCCheck/$file.curry ]; then echo "*********** file doesn't exist: $file"; fi
diff --git a/test/typeclasses/TCCheck/DuplicateInstances2.curry b/test/typeclasses/TCCheck/DuplicateInstances2.curry
new file mode 100644
index 0000000000000000000000000000000000000000..168603de5820bab3f76df4d94b137347a82eedee
--- /dev/null
+++ b/test/typeclasses/TCCheck/DuplicateInstances2.curry
@@ -0,0 +1,15 @@
+
+class C a where
+
+class C a => D a where
+
+data T a = T a
+
+class F a where
+
+instance F a => C (T a) where
+
+instance F a => D (T a) where
+
+instance F a => D (T a) where
+