Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7159287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:12:21+00:00 2026-05-28T13:12:21+00:00

I have a scenario that is causing a type mismatch that I cannot seem

  • 0

I have a scenario that is causing a type mismatch that I cannot seem to resolve. Here’s a simplified version of the code:

abstract class Msg

trait Channel[M <: Msg] {
  def receive(): M
  def ack(envelope: M)
}

object ChannelSender {
  private var channel : Channel[_ <: Msg] = _
  def assignChannel(channel : Channel[_ <: Msg]) = this.channel = channel

  def test() {
    val msg = channel.receive()
    channel.ack(msg) // Type mismatch here
  }
}

The error from the compiler is:

type mismatch; found : msg.type (with underlying type
com.msgtest.Envelope) required: _$1 where type _$1 <:
com.msgtest.Envelope

What sort of changes could I make to get this working? Additionally, the changes require that the following concrete implementation compile:

class SomeMsg extends Msg

object SomeChannel extends Channel[SomeMsg] {
  def receive(): SomeMsg = { null.asInstanceOf[SomeMsg] }
  def ack(envelope: SomeMsg) {}
}

object Setup {
  ChannelSender.assignChannel(SomeChannel)
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:12:22+00:00Added an answer on May 28, 2026 at 1:12 pm

    I could get it to compile under Scala 2.9 with two changes,

    trait Channel[M <: Msg] {
      type M2 = M       // Introduce a type member that's externally visible
      def receive(): M2
      def ack(envelope: M2)
    }
    
    object ChannelSender {
      private var channel : Channel[_ <: Msg] = _
      def assignChannel(channel : Channel[_ <: Msg]) = this.channel = channel
    
      def test() {
        val c = channel  // An immutable value, so that c.M2 is stable
        val msg = c.receive()
        c.ack(msg)       // OK now
      }
    }
    

    The first change is to use an immutable value val c = channel, so that the path dependent type c.M2 always means the same thing. The second change is to introduce a type member type M2 = M in trait Channel. I’m not totally sure why this is necessary (could it be a bug?). One thing to note is that c.M2 is a valid type, whereas c.M is undefined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the scenario that I have. I have a cvs repository in one
I have a scenario that does not seem to be covered in any of
I have a path defined: when /the admin home\s?page/ /admin/ I have scenario that
I have a scenario that my load balancer translates port 80 from outside into
I have a scenario that I haven't been able to solve: I'm toying around
I'm trying to write a Cucumber scenario that requires me to have a logged
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
Common scenario: I have a library that uses other libraries. For example, a math
The scenario: we have a web system that automatically generates office 2003 excel files
Scenario: I have a text file that has pipe (as in the | character)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.