diff options
author | Paul Phillips <paulp@improving.org> | 2013-03-02 11:17:40 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-03-02 11:18:08 -0800 |
commit | e1ab60e60e169a874d7cacc2287ae89238e20b76 (patch) | |
tree | 83a12d9dc3eaf9fb886afc416b31d31e1537f3b5 | |
parent | b457b6c477dfd5f3517d31bbbd8e2db5bd8386d2 (diff) | |
download | scala-e1ab60e60e169a874d7cacc2287ae89238e20b76.tar.gz scala-e1ab60e60e169a874d7cacc2287ae89238e20b76.tar.bz2 scala-e1ab60e60e169a874d7cacc2287ae89238e20b76.zip |
Simplified correspondingTypeArgument based on reviewer feedback.
-rw-r--r-- | src/reflect/scala/reflect/internal/Types.scala | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index 9cb7a71592..4794052e05 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -4438,22 +4438,17 @@ trait Types extends api.Types { self: SymbolTable => private def correspondingTypeArgument(lhs: Type, rhs: Type): Type = { val TypeRef(_, lhsSym, lhsArgs) = lhs val TypeRef(_, rhsSym, rhsArgs) = rhs - val clazz = lhsSym.safeOwner - require(clazz == rhsSym, s"$lhsSym is not a type parameter of $rhsSym") + require(lhsSym.safeOwner == rhsSym, s"$lhsSym is not a type parameter of $rhsSym") - def fail: Type = ( - // don't be too zealous with the exceptions, see #2641 - if (clazz.tpe_*.parents exists typeIsErroneous) ErrorType - else abort(s"something is wrong: cannot make sense of type application\n $lhs\n $rhs") - ) - def loop(params: List[Symbol], args: List[Type]): Type = ( - // didn't find lhsSym amongst the params - if (params.isEmpty || args.isEmpty) fail - else if (params.head eq lhsSym) args.head - else loop(params.tail, args.tail) - ) - // @M! don't just replace the whole thing, might be followed by type application - appliedType(loop(rhsSym.typeParams, rhsArgs), lhsArgs mapConserve this) + // Find the type parameter position; we'll use the corresponding argument + val argIndex = rhsSym.typeParams indexOf lhsSym + + if (argIndex >= 0 && argIndex < rhsArgs.length) // @M! don't just replace the whole thing, might be followed by type application + appliedType(rhsArgs(argIndex), lhsArgs mapConserve this) + else if (rhsSym.tpe_*.parents exists typeIsErroneous) // don't be too zealous with the exceptions, see #2641 + ErrorType + else + abort(s"something is wrong: cannot make sense of type application\n $lhs\n $rhs") } // 0) @pre: `classParam` is a class type parameter |