Buggy code:
public class HaskellUtil { @ NotNull public static List < PsiNamedElement > findDefinitionNode ( @ NotNull Project project , @ Nullable String name , @ Nullable PsiNamedElement e ) { } public static void findDefinitionNode ( @ Nullable HaskellFile file , @ Nullable String name , @ Nullable PsiNamedElement e , @ NotNull List < PsiNamedElement > result ) { } @ NotNull public static List < PsiNamedElement > findDefinitionNodes ( @ Nullable HaskellFile haskellFile , @ Nullable String name ) { } @ NotNull public static List < PsiNamedElement > findDefinitionNodes ( @ NotNull Project project ) { } @ NotNull public static List < PsiNamedElement > findDefinitionNodes ( @ NotNull HaskellFile psiFile ) { } public static boolean definitionNode ( @ NotNull PsiNamedElement e ) { } public static boolean definitionNode ( @ NotNull HaskellConid e ) { } public static boolean definitionNode ( @ NotNull HaskellVarid e ) { } public static boolean definitionNode ( @ NotNull ASTNode node ) { } @ Nullable public static String getQualifiedPrefix ( @ NotNull PsiElement e ) { } @ NotNull public static Set < String > getPotentialDefinitionModuleNames ( @ NotNull PsiElement e , @ NotNull List < HaskellPsiUtil . Import > imports ) { } @ Nullable public static PsiElement lookForFunOrPatDeclWithCorrectName ( @ NotNull PsiElement element , @ NotNull String matcher ) { } public static List < HaskellVarid > extractAllHaskellVarids ( HaskellPat pat ) { } private static PsiElement checkForMatchingVariable ( PsiElement child , String matcher ) { } public static boolean isInsideBody ( @ NotNull PsiElement position ) { } @ NotNull public static List < PsiElement > matchWhereClausesInScope ( @ NotNull PsiNamedElement myElement , String name ) { } @ NotNull public static List < PsiElement > getAllDefinitionsInWhereClausesInScope ( @ NotNull PsiElement myElement ) { } @ NotNull private static List < PsiElement > checkWhereClausesInScopeForVariableDeclaration ( @ NotNull PsiElement myElement , String matcher ) { } @ Nullable private static PsiElement checkWhereClause ( @ NotNull PsiElement where , String matcher ) { } @ NotNull public static List < PsiElement > matchLocalDefinitionsInScope ( PsiElement element , String name ) { } @ NotNull public static List < PsiElement > getAllDefinitionsInScope ( PsiElement element ) { } @ NotNull private static List < PsiElement > checkLocalDefinitionsForVariableDeclarations ( PsiElement element , String matcher ) { List < PsiElement > results = Lists . newArrayList ( ) ; PsiElement parent = element ; do { PsiElement prevSibling = parent . getPrevSibling ( ) ; while ( prevSibling != null ) { PsiElement possibleMatch = HaskellUtil . lookForFunOrPatDeclWithCorrectName ( prevSibling , matcher ) ; if ( possibleMatch != null ) { results . add ( possibleMatch ) ; } <START_BUG> if ( prevSibling instanceof HaskellPat ) { <END_BUG> List < HaskellVarid > varIds = HaskellUtil . extractAllHaskellVarids ( ( ( HaskellPat ) ( prevSibling ) ) ) ; for ( HaskellVarid varId : varIds ) { if ( varId . getName ( ) . matches ( matcher ) ) { results . add ( varId ) ; } } } if ( prevSibling instanceof HaskellVarid ) { HaskellVarid varId = ( ( HaskellVarid ) ( prevSibling ) ) ; if ( varId . getName ( ) . matches ( matcher ) ) { results . add ( varId ) ; } } prevSibling = prevSibling . getPrevSibling ( ) ; } parent = parent . getParent ( ) ; } while ( ! ( parent instanceof PsiFile ) ) ; return results ; } public static List < PsiElement > matchGlobalNamesUnqualified ( PsiElement psiElement , List < PsiNamedElement > namedElements , List < HaskellPsiUtil . Import > importDeclarations ) { } public static List < PsiElementResolveResult > matchGlobalNamesQualified ( List < PsiNamedElement > namedElements , String qualifiedCallName , List < HaskellPsiUtil . Import > importDeclarations ) { } @ NotNull public static String getModuleName ( @ NotNull PsiElement element ) { } public static boolean importPresentAndUnqualifiedImport ( @ NotNull String moduleName , @ NotNull List < HaskellPsiUtil . Import > importDeclarations ) { } private static Import findCorrespondingImportDeclaration ( String qualifiedCallName , List < HaskellPsiUtil . Import > importDeclarations ) { } }

Fix:
if ( ( prevSibling instanceof HaskellPat ) && ( parent instanceof HaskellExp ) ) {