<commit_before>package dotty.tools
package dotc
package typer

import core._
import ast._
import Contexts._
import Types._
import Flags._
import Names._
import StdNames._
import Symbols._
import Trees._
import TreeInfo._
import ProtoTypes._
import Scopes._
import CheckRealizable._
import ErrorReporting.errorTree
import rewrites.Rewrites.patch
import util.Spans.Span

import util.SourcePosition
import util.Spans.Span
import rewrites.Rewrites.patch
import transform.SymUtils._
import transform.ValueClasses._
import Decorators._
import ErrorReporting.{err, errorType}
import config.Printers.{typr, patmatch}
import NameKinds.DefaultGetterName
import NameOps._
import SymDenotations.{NoCompleter, NoDenotation}
import Applications.unapplyArgs
import transform.patmat.SpaceEngine.isIrrefutableUnapply


import collection.mutable
import reporting.diagnostic.Message
import reporting.diagnostic.messages._
import scala.internal.Chars.isOperatorPart

object Checking {
  import tpd._

  /** A general checkBounds method that can be used for TypeApply nodes as
   *  well as for AppliedTypeTree nodes. Also checks that type arguments to
   *  *-type parameters are fully applied.
   *  See TypeOps.boundsViolations for an explanation of the parameters.
   */
  def checkBounds(args: List[tpd.Tree], boundss: List[TypeBounds], instantiate: (Type, List[Type]) => Type, app: Type = NoType)(implicit ctx: Context): Unit = {
    args.lazyZip(boundss).foreach { (arg, bound) =>
      if (!bound.isLambdaSub && !arg.tpe.hasSimpleKind)
        errorTree(arg, MissingTypeParameterInTypeApp(arg.tpe))
    }
    for ((arg, which, bound) <- ctx.boundsViolations(args, boundss, instantiate, app))
      ctx.error(
          DoesNotConformToBound(arg.tpe, which, bound)(err),
          arg.sourcePos.focus)
  }

  /** Check that type arguments `args` conform to corresponding bounds in `tl`
   *  Note: This does not check the bounds of AppliedTypeTrees. These
   *  are handled by method checkAppliedType below.
   */
  def checkBounds(args: List[tpd.Tree], tl: TypeLambda)(implicit ctx: Context): Unit =
    checkBounds(args, tl.paramInfos, _.substParams(tl, _))

  /** Check applied type trees for well-formedness. This means
   *   - all arguments are within their corresponding bounds
   *   - if type is a higher-kinded application with wildcard arguments,
   *     check that it or one of its supertypes can be reduced to a normal application.
   *     Unreducible applications correspond to general existentials, and we
   *     cannot handle those.
   */
  def checkAppliedType(tree: AppliedTypeTree, boundsCheck: Boolean)(implicit ctx: Context): Unit = {
    val AppliedTypeTree(tycon, args) = tree
    // If `args` is a list of named arguments, return corresponding type parameters,
    // otherwise return type parameters unchanged
    val tparams = tycon.tpe.typeParams
    def argNamed(tparam: ParamInfo) = args.find {
      case NamedArg(name, _) => name == tparam.paramName
      case _ => false
    }.getOrElse(TypeTree(tparam.paramRef))
    val orderedArgs = if (hasNamedArg(args)) tparams.map(argNamed) else args
    val bounds = tparams.map(_.paramInfoAsSeenFrom(tree.tpe).bounds)
    def instantiate(bound: Type, args: List[Type]) =
      tparams match
        case LambdaParam(lam, _) :: _ =>
          HKTypeLambda.fromParams(tparams, bound).appliedTo(args)
        case _ =>
          bound // paramInfoAsSeenFrom already took care of instantiation in this case
    if (boundsCheck) checkBounds(orderedArgs, bounds, instantiate, tree.tpe)
<commit_msg>Drop handling of named type arguments in checkAppliedType<commit_after>package dotty.tools
package dotc
package typer

import core._
import ast._
import Contexts._
import Types._
import Flags._
import Names._
import StdNames._
import Symbols._
import Trees._
import TreeInfo._
import ProtoTypes._
import Scopes._
import CheckRealizable._
import ErrorReporting.errorTree
import rewrites.Rewrites.patch
import util.Spans.Span

import util.SourcePosition
import util.Spans.Span
import rewrites.Rewrites.patch
import transform.SymUtils._
import transform.ValueClasses._
import Decorators._
import ErrorReporting.{err, errorType}
import config.Printers.{typr, patmatch}
import NameKinds.DefaultGetterName
import NameOps._
import SymDenotations.{NoCompleter, NoDenotation}
import Applications.unapplyArgs
import transform.patmat.SpaceEngine.isIrrefutableUnapply


import collection.mutable
import reporting.diagnostic.Message
import reporting.diagnostic.messages._
import scala.internal.Chars.isOperatorPart

object Checking {
  import tpd._

  /** A general checkBounds method that can be used for TypeApply nodes as
   *  well as for AppliedTypeTree nodes. Also checks that type arguments to
   *  *-type parameters are fully applied.
   *  See TypeOps.boundsViolations for an explanation of the parameters.
   */
  def checkBounds(args: List[tpd.Tree], boundss: List[TypeBounds], instantiate: (Type, List[Type]) => Type, app: Type = NoType)(implicit ctx: Context): Unit = {
    args.lazyZip(boundss).foreach { (arg, bound) =>
      if (!bound.isLambdaSub && !arg.tpe.hasSimpleKind)
        errorTree(arg, MissingTypeParameterInTypeApp(arg.tpe))
    }
    for ((arg, which, bound) <- ctx.boundsViolations(args, boundss, instantiate, app))
      ctx.error(
          DoesNotConformToBound(arg.tpe, which, bound)(err),
          arg.sourcePos.focus)
  }

  /** Check that type arguments `args` conform to corresponding bounds in `tl`
   *  Note: This does not check the bounds of AppliedTypeTrees. These
   *  are handled by method checkAppliedType below.
   */
  def checkBounds(args: List[tpd.Tree], tl: TypeLambda)(implicit ctx: Context): Unit =
    checkBounds(args, tl.paramInfos, _.substParams(tl, _))

  /** Check applied type trees for well-formedness. This means
   *   - all arguments are within their corresponding bounds
   *   - if type is a higher-kinded application with wildcard arguments,
   *     check that it or one of its supertypes can be reduced to a normal application.
   *     Unreducible applications correspond to general existentials, and we
   *     cannot handle those.
   */
  def checkAppliedType(tree: AppliedTypeTree, boundsCheck: Boolean)(implicit ctx: Context): Unit = {
    val AppliedTypeTree(tycon, args) = tree
    // If `args` is a list of named arguments, return corresponding type parameters,
    // otherwise return type parameters unchanged
    val tparams = tycon.tpe.typeParams
    val bounds = tparams.map(_.paramInfoAsSeenFrom(tree.tpe).bounds)
    def instantiate(bound: Type, args: List[Type]) =
      tparams match
        case LambdaParam(lam, _) :: _ =>
          HKTypeLambda.fromParams(tparams, bound).appliedTo(args)
        case _ =>
          bound // paramInfoAsSeenFrom already took care of instantiation in this case
    if (boundsCheck) checkBounds(args, bounds, instantiate, tree.tpe)

{'fraction_non_alphanumeric': 0.08623188405797101, 'fraction_numerical': 0.0, 'mean_word_length': 4.004350978970268, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6433422', 'n_tokens_mistral': 2036, 'n_tokens_neox': 1975, 'n_words': 631}