<commit_before>package org.jetbrains.plugins.scala.lang.psi.api

import base.patterns.ScBindingPattern
import base.ScLiteral
import expr.ScExpression
import collection.mutable.ArrayBuffer
import org.jetbrains.plugins.scala.lang.psi.types.Compatibility.Expression
import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult
import org.jetbrains.plugins.scala.lang.psi.implicits.ImplicitParametersCollector
import statements.params.ScParameter
import statements.ScFunction
import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil.SafeCheckException
import org.jetbrains.plugins.scala.lang.psi.{types, ScalaPsiUtil}
import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult, TypingContext}
import org.jetbrains.plugins.scala.lang.psi.types._
import nonvalue.{Parameter, ScMethodType, ScTypePolymorphicType}
import toplevel.typedef.ScObject
import com.intellij.psi.PsiElement
import org.jetbrains.plugins.scala.extensions.toPsiClassExt
import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory
import org.jetbrains.plugins.scala.lang.languageLevel.ScalaLanguageLevel

/**
 * @author <NAME>
 */

object InferUtil {
  class A[A, B]
  class BB[A, B]

  def foo[A, B, C](x: A)(implicit a: A[A, B], b: BB[B, C]): C = sys.exit()

  implicit def a[T]: A[T, List[T]] = new A
  implicit def b[T]: BB[T, List[T]] = new BB

  foo("")

  /**
   * This method can find implicit parameters for given MethodType
   * @param res MethodType or PolymorphicType(MethodType)
   * @param element place to find implicit parameters
   * @param check if true can throw SafeCheckException if it not found not ambiguous implicit parameters
   * @return updated type and sequence of implicit parameters
   */
  def updateTypeWithImplicitParameters(res: ScType, element: PsiElement,
                                       check: Boolean,
                                       searchImplicitsRecursively: Int = 0,
                                       checkAnyway: Boolean = false): (ScType, Option[Seq[ScalaResolveResult]]) = {
    var resInner = res
    var implicitParameters: Option[Seq[ScalaResolveResult]] = None
    res match {
      case t@ScTypePolymorphicType(mt@ScMethodType(retType, params, impl), typeParams) if !impl =>
        // See SCL-3516
        val (updatedType, ps) = 
          updateTypeWithImplicitParameters(t.copy(internalType = retType), element, check, checkAnyway = checkAnyway)
        implicitParameters = ps
        updatedType match {
          case tpt: ScTypePolymorphicType =>
            resInner = t.copy(internalType = mt.copy(returnType = tpt.internalType)(mt.project, mt.scope),
              typeParameters = tpt.typeParameters)
          case _ => //shouldn't be there
            resInner = t.copy(internalType = mt.copy(returnType = updatedType)(mt.project, mt.scope))
        }
      case t@ScTypePolymorphicType(ScMethodType(retType, params, impl), typeParams) if impl =>
        val polymorphicSubst = t.polymorphicTypeSubstitutor
        val abstractSubstitutor: ScSubstitutor = t.abstractTypeSubstitutor<commit_msg>Fixe compilation.<commit_after>package org.jetbrains.plugins.scala.lang.psi.api

import base.patterns.ScBindingPattern
import base.ScLiteral
import expr.ScExpression
import collection.mutable.ArrayBuffer
import org.jetbrains.plugins.scala.lang.psi.types.Compatibility.Expression
import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult
import org.jetbrains.plugins.scala.lang.psi.implicits.ImplicitParametersCollector
import statements.params.ScParameter
import statements.ScFunction
import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil.SafeCheckException
import org.jetbrains.plugins.scala.lang.psi.{types, ScalaPsiUtil}
import org.jetbrains.plugins.scala.lang.psi.types.result.{Success, TypeResult, TypingContext}
import org.jetbrains.plugins.scala.lang.psi.types._
import nonvalue.{Parameter, ScMethodType, ScTypePolymorphicType}
import toplevel.typedef.ScObject
import com.intellij.psi.PsiElement
import org.jetbrains.plugins.scala.extensions.toPsiClassExt
import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory
import org.jetbrains.plugins.scala.lang.languageLevel.ScalaLanguageLevel

/**
 * @author <NAME>
 */

object InferUtil {
  /**
   * This method can find implicit parameters for given MethodType
   * @param res MethodType or PolymorphicType(MethodType)
   * @param element place to find implicit parameters
   * @param check if true can throw SafeCheckException if it not found not ambiguous implicit parameters
   * @return updated type and sequence of implicit parameters
   */
  def updateTypeWithImplicitParameters(res: ScType, element: PsiElement,
                                       check: Boolean,
                                       searchImplicitsRecursively: Int = 0,
                                       checkAnyway: Boolean = false): (ScType, Option[Seq[ScalaResolveResult]]) = {
    var resInner = res
    var implicitParameters: Option[Seq[ScalaResolveResult]] = None
    res match {
      case t@ScTypePolymorphicType(mt@ScMethodType(retType, params, impl), typeParams) if !impl =>
        // See SCL-3516
        val (updatedType, ps) = 
          updateTypeWithImplicitParameters(t.copy(internalType = retType), element, check, checkAnyway = checkAnyway)
        implicitParameters = ps
        updatedType match {
          case tpt: ScTypePolymorphicType =>
            resInner = t.copy(internalType = mt.copy(returnType = tpt.internalType)(mt.project, mt.scope),
              typeParameters = tpt.typeParameters)
          case _ => //shouldn't be there
            resInner = t.copy(internalType = mt.copy(returnType = updatedType)(mt.project, mt.scope))
        }
      case t@ScTypePolymorphicType(ScMethodType(retType, params, impl), typeParams) if impl =>
        val polymorphicSubst = t.polymorphicTypeSubstitutor
        val abstractSubstitutor: ScSubstitutor = t.abstractTypeSubstitutor
{'fraction_non_alphanumeric': 0.09149007736293306, 'fraction_numerical': 0.0016818028927009755, 'mean_word_length': 3.6352299298519095, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '676399', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1672, 'n_words': 378}