asinduvg opened a new issue, #1933:
URL: https://github.com/apache/pekko/issues/1933

   ## Bug Description
   messageAdapter closures appear to capture the wrong enum value when created 
inline in Scala, causing both adapters to use the same Tag value instead of 
their respective Self/Peer values.
   
   ### Expected Behavior
   Two separate messageAdapters should capture different enum values:
   
   First adapter should capture `Tag.Self`
   Second adapter should capture `Tag.Peer`
   
   **Expected console output:**
   ```
   ItemStored(..., Self)
   ItemStored(..., Peer)
   ```
   ### Actual Behavior
   Both messageAdapters are capturing `Tag.Peer`, resulting in identical tags 
for different operations.
   
   **Actual console output showing the problem:**
   ```
   ItemStored(url1, Peer)
   ItemStored(url2, Peer)
   ```
   
   Notice: Both ItemStored messages show `Tag.Peer` instead of the expected 
`Tag.Self` and `Tag.Peer`.
   
   ### Minimal Reproducible Example
   ```
   import org.apache.pekko.actor.typed.scaladsl.Behaviors
   import org.apache.pekko.actor.typed.{ActorRef, Behavior}
   
   object TestActor:
     sealed trait Command
     private final case class ItemStored(url: String, tag: Tag) extends Command
   
     private enum Tag:
       case Self
       case Peer
   
     case class ExternalMessage(replyTo: ActorRef[String])
   
     def apply(): Behavior[Command] =
       Behaviors.receive: (ctx, msg) =>
         msg match
           case _ =>
             val externalActor = ctx.spawnAnonymous(ExternalActor())
   
             // BUG: Both of these capture Tag.Peer instead of their respective 
values
             externalActor ! ExternalMessage(
               ctx.messageAdapter[String]: response =>
                 ItemStored(response, Tag.Self)  // Should capture Tag.Self but 
captures Tag.Peer
             )
   
             externalActor ! ExternalMessage(
               ctx.messageAdapter[String]: response =>
                 ItemStored(response, Tag.Peer)  // This works correctly
             )
   
             Behaviors.receive: (ctx, msg) =>
               msg match
                 case ItemStored(url, tag) =>
                   println(s"ItemStored($url, $tag)")  // Shows both as Peer
                   Behaviors.same
   
   object ExternalActor:
     def apply(): Behavior[TestActor.ExternalMessage] =
       Behaviors.receive: (ctx, msg) =>
         msg match
           case TestActor.ExternalMessage(replyTo) =>
             replyTo ! "some-url"
             Behaviors.same
   ```
   
   ### Environment
   - Pekko version: 1.1.3
   - Scala version: 3.3.5
   - Java version: Amazon.com Inc. Java 21.0.6
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@pekko.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@pekko.apache.org
For additional commands, e-mail: notifications-h...@pekko.apache.org

Reply via email to