Skip to content
This repository
Browse code

Simplified correspondingTypeArgument based on reviewer feedback.

  • Loading branch information...
commit e1ab60e60e169a874d7cacc2287ae89238e20b76 1 parent b457b6c
Paul Phillips paulp authored

Showing 1 changed file with 10 additions and 15 deletions. Show diff stats Hide diff stats

  1. +10 15 src/reflect/scala/reflect/internal/Types.scala
25 src/reflect/scala/reflect/internal/Types.scala
@@ -4438,22 +4438,17 @@ trait Types extends api.Types { self: SymbolTable =>
4438 4438 private def correspondingTypeArgument(lhs: Type, rhs: Type): Type = {
4439 4439 val TypeRef(_, lhsSym, lhsArgs) = lhs
4440 4440 val TypeRef(_, rhsSym, rhsArgs) = rhs
4441   - val clazz = lhsSym.safeOwner
4442   - require(clazz == rhsSym, s"$lhsSym is not a type parameter of $rhsSym")
  4441 + require(lhsSym.safeOwner == rhsSym, s"$lhsSym is not a type parameter of $rhsSym")
4443 4442
4444   - def fail: Type = (
4445   - // don't be too zealous with the exceptions, see #2641
4446   - if (clazz.tpe_*.parents exists typeIsErroneous) ErrorType
4447   - else abort(s"something is wrong: cannot make sense of type application\n $lhs\n $rhs")
4448   - )
4449   - def loop(params: List[Symbol], args: List[Type]): Type = (
4450   - // didn't find lhsSym amongst the params
4451   - if (params.isEmpty || args.isEmpty) fail
4452   - else if (params.head eq lhsSym) args.head
4453   - else loop(params.tail, args.tail)
4454   - )
4455   - // @M! don't just replace the whole thing, might be followed by type application
4456   - appliedType(loop(rhsSym.typeParams, rhsArgs), lhsArgs mapConserve this)
  4443 + // Find the type parameter position; we'll use the corresponding argument
  4444 + val argIndex = rhsSym.typeParams indexOf lhsSym
  4445 +
  4446 + if (argIndex >= 0 && argIndex < rhsArgs.length) // @M! don't just replace the whole thing, might be followed by type application
  4447 + appliedType(rhsArgs(argIndex), lhsArgs mapConserve this)
  4448 + else if (rhsSym.tpe_*.parents exists typeIsErroneous) // don't be too zealous with the exceptions, see #2641
  4449 + ErrorType
  4450 + else
  4451 + abort(s"something is wrong: cannot make sense of type application\n $lhs\n $rhs")
4457 4452 }
4458 4453
4459 4454 // 0) @pre: `classParam` is a class type parameter

0 comments on commit e1ab60e

Please sign in to comment.
Something went wrong with that request. Please try again.