Program: 163075
Project: 163075
Buggy source:
@NotNull public static PsiElement fullyResolveAlias(@NotNull QualifiableAlias alias,@Nullable PsiReference startingReference){
  PsiElement fullyResolved;
  PsiElement currentResolved=alias;
  PsiReference reference=startingReference;
  do {
    if (reference == null) {
      reference=currentResolved.getReference();
    }
    if (reference != null) {
      if (reference instanceof PsiPolyVariantReference) {
        PsiPolyVariantReference polyVariantReference=(PsiPolyVariantReference)reference;
        ResolveResult[] resolveResults=polyVariantReference.multiResolve(false);
        int resolveResultCount=resolveResults.length;
        if (resolveResultCount == 0) {
          fullyResolved=currentResolved;
          break;
        }
 else         if (resolveResultCount == 1) {
          ResolveResult resolveResult=resolveResults[0];
          PsiElement nextResolved=resolveResult.getElement();
          if (nextResolved == null || nextResolved.isEquivalentTo(currentResolved)) {
            fullyResolved=currentResolved;
            break;
          }
 else {
            currentResolved=nextResolved;
          }
        }
 else {
          PsiElement nextResolved=null;
          for (          ResolveResult resolveResult : resolveResults) {
            PsiElement resolveResultElement=resolveResult.getElement();
            if (resolveResultElement != null && resolveResultElement instanceof Call && isModular((Call)resolveResultElement)) {
              nextResolved=resolveResultElement;
              break;
            }
          }
          if (nextResolved == null || nextResolved.isEquivalentTo(currentResolved)) {
            fullyResolved=currentResolved;
            break;
          }
 else {
            currentResolved=nextResolved;
          }
        }
      }
 else {
        PsiElement nextResolved=reference.resolve();
        if (nextResolved == null || nextResolved.isEquivalentTo(currentResolved)) {
          fullyResolved=currentResolved;
          break;
        }
 else {
          currentResolved=nextResolved;
        }
      }
    }
 else {
      fullyResolved=currentResolved;
      break;
    }
    reference=null;
  }
 while (true);
  return fullyResolved;
}

Fixed version (ground truth):
@NotNull public static PsiElement fullyResolveAlias(@NotNull QualifiableAlias alias,@Nullable PsiReference startingReference){
  PsiElement fullyResolved;
  PsiElement currentResolved=alias;
  PsiReference reference=startingReference;
  do {
    if (reference == null) {
      reference=currentResolved.getReference();
    }
    if (reference != null) {
      if (reference instanceof PsiPolyVariantReference) {
        PsiPolyVariantReference polyVariantReference=(PsiPolyVariantReference)reference;
        ResolveResult[] resolveResults=polyVariantReference.multiResolve(false);
        int resolveResultCount=resolveResults.length;
        if (resolveResultCount == 0) {
          fullyResolved=currentResolved;
          break;
        }
 else         if (resolveResultCount == 1) {
          ResolveResult resolveResult=resolveResults[0];
          PsiElement nextResolved=resolveResult.getElement();
          if (nextResolved != null && nextResolved instanceof Call && isModular((Call)nextResolved)) {
            fullyResolved=nextResolved;
            break;
          }
          if (nextResolved == null || nextResolved.isEquivalentTo(currentResolved)) {
            fullyResolved=currentResolved;
            break;
          }
 else {
            currentResolved=nextResolved;
          }
        }
 else {
          PsiElement nextResolved=null;
          for (          ResolveResult resolveResult : resolveResults) {
            PsiElement resolveResultElement=resolveResult.getElement();
            if (resolveResultElement != null && resolveResultElement instanceof Call && isModular((Call)resolveResultElement)) {
              nextResolved=resolveResultElement;
              break;
            }
          }
          if (nextResolved == null) {
            fullyResolved=currentResolved;
          }
 else {
            fullyResolved=nextResolved;
          }
          break;
        }
      }
 else {
        PsiElement nextResolved=reference.resolve();
        if (nextResolved == null || nextResolved.isEquivalentTo(currentResolved)) {
          fullyResolved=currentResolved;
          break;
        }
 else {
          currentResolved=nextResolved;
        }
      }
    }
 else {
      fullyResolved=currentResolved;
      break;
    }
    reference=null;
  }
 while (true);
  return fullyResolved;
}