This is an automated email from the ASF dual-hosted git repository.

He-Pin pushed a commit to branch pr-1067
in repository https://gitbox.apache.org/repos/asf/pekko-http.git

commit f6c4c920c6551f1c40e0d04382a2ea1a8d052c91
Author: 虎鸣 <[email protected]>
AuthorDate: Mon Jun 15 19:47:46 2026 +0800

    fix: resolve ambiguous implicit values in PathMatcher.scala
    
    Motivation:
    The PR #1067 changes to PathMatcher.scala introduced `implicit val tupleEv`
    and `implicit val tupleL` declarations that shadow the `ev` member of the
    PathMatcher class inside anonymous class bodies, causing "ambiguous implicit
    values" compilation errors on Scala 2.13.
    
    Modification:
    Remove the redundant implicit val declarations and pass the Tuple evidence
    explicitly to the PathMatcher constructor instead. For `repeat` and 
`optional`,
    pass `lift.OutIsTuple` directly. For `provide` and `apply`, pass `ev` 
directly
    and also pass it explicitly to `Matched` calls.
    
    Result:
    PathMatcher.scala compiles without ambiguous implicit errors on Scala 2.13
    while maintaining Scala 3 forward compatibility.
    
    Tests:
    Not run - compilation fix
    
    References:
    Refs #1067
---
 .../pekko/http/scaladsl/server/PathMatcher.scala   | 31 ++++++++--------------
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git 
a/http/src/main/scala/org/apache/pekko/http/scaladsl/server/PathMatcher.scala 
b/http/src/main/scala/org/apache/pekko/http/scaladsl/server/PathMatcher.scala
index 63d55ff90..af10a00f9 100644
--- 
a/http/src/main/scala/org/apache/pekko/http/scaladsl/server/PathMatcher.scala
+++ 
b/http/src/main/scala/org/apache/pekko/http/scaladsl/server/PathMatcher.scala
@@ -99,9 +99,8 @@ abstract class PathMatcher[L](implicit val ev: Tuple[L]) 
extends (Path => PathMa
    * </table>
    */
   def repeat(min: Int, max: Int, separator: PathMatcher0 = 
PathMatchers.Neutral)(
-      implicit lift: PathMatcher.Lift[L, List]): PathMatcher[lift.Out] = {
-    implicit val tupleEv: Tuple[lift.Out] = lift.OutIsTuple
-    new PathMatcher[lift.Out]() {
+      implicit lift: PathMatcher.Lift[L, List]): PathMatcher[lift.Out] =
+    new PathMatcher[lift.Out]()(lift.OutIsTuple) {
       require(min >= 0, "`min` must be >= 0")
       require(max >= min, "`max` must be >= `min`")
 
@@ -128,7 +127,6 @@ abstract class PathMatcher[L](implicit val ev: Tuple[L]) 
extends (Path => PathMa
         else done
       }
     }
-  }
 }
 
 object PathMatcher extends ImplicitPathMatcherConstruction {
@@ -158,12 +156,10 @@ object PathMatcher extends 
ImplicitPathMatcherConstruction {
   /**
    * Creates a PathMatcher that always matches, consumes nothing and extracts 
the given Tuple of values.
    */
-  def provide[L](extractions: L)(implicit ev: Tuple[L]): PathMatcher[L] = {
-    implicit val tupleL: Tuple[L] = ev
-    new PathMatcher[L] {
-      def apply(path: Path) = Matched(path, extractions)
+  def provide[L](extractions: L)(implicit ev: Tuple[L]): PathMatcher[L] =
+    new PathMatcher[L]()(ev) {
+      def apply(path: Path) = Matched(path, extractions)(ev)
     }
-  }
 
   /**
    * Creates a PathMatcher that matches and consumes the given path prefix and 
extracts the given list of extractions.
@@ -171,13 +167,10 @@ object PathMatcher extends 
ImplicitPathMatcherConstruction {
    */
   def apply[L](prefix: Path, extractions: L)(implicit ev: Tuple[L]): 
PathMatcher[L] =
     if (prefix.isEmpty) provide(extractions)
-    else {
-      implicit val tupleL: Tuple[L] = ev
-      new PathMatcher[L] {
-        def apply(path: Path) =
-          if (path.startsWith(prefix)) 
Matched(path.dropChars(prefix.charCount), extractions)
-          else Unmatched
-      }
+    else new PathMatcher[L]()(ev) {
+      def apply(path: Path) =
+        if (path.startsWith(prefix)) Matched(path.dropChars(prefix.charCount), 
extractions)(ev)
+        else Unmatched
     }
 
   /** Provoke implicit conversions to PathMatcher to be applied */
@@ -190,15 +183,13 @@ object PathMatcher extends 
ImplicitPathMatcherConstruction {
   }
 
   implicit class EnhancedPathMatcher[L](underlying: PathMatcher[L]) {
-    def optional(implicit lift: PathMatcher.Lift[L, Option]): 
PathMatcher[lift.Out] = {
-      implicit val tupleEv: Tuple[lift.Out] = lift.OutIsTuple
-      new PathMatcher[lift.Out]() {
+    def optional(implicit lift: PathMatcher.Lift[L, Option]): 
PathMatcher[lift.Out] =
+      new PathMatcher[lift.Out]()(lift.OutIsTuple) {
         def apply(path: Path) = underlying(path) match {
           case Matched(rest, extractions) => Matched(rest, lift(extractions))
           case Unmatched                  => Matched(path, lift())
         }
       }
-    }
     def ?(implicit lift: PathMatcher.Lift[L, Option]): PathMatcher[lift.Out] = 
optional(lift)
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to