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 8315891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:13:59+00:00 2026-06-08T21:13:59+00:00

This is a much simpler version of my earlier post ambiguous implicit conversion errors

  • 0

This is a much simpler version of my earlier post ambiguous implicit conversion errors

Here is a code snippet from the post How can I chain implicits in Scala?

class A(val n: Int)
class B(val m: Int, val n: Int)
class C(val m: Int, val n: Int, val o: Int) {
  def total = m + n + o
}

object T2 {
  implicit def toA(n: Int): A = new A(n)
  implicit def aToB[A1 <% A](a: A1): B = new B(a.n, a.n)
  implicit def bToC[B1 <% B](b: B1): C = new C(b.m, b.n, b.m + b.n)

  // works
  println(5.total)
  println(new A(5).total)
  println(new B(5, 5).total)
  println(new C(5, 5, 10).total)
}

Now if I add a class D and implicit def dToC as follows, I get errors at locations shown in the snippet.

class A(val n: Int)
class B(val m: Int, val n: Int)
class D(val m: Int, val n: Int) //Added by me
class C(val m: Int, val n: Int, val o: Int) {
    def total = m + n + o
}

object T2 {
  implicit def toA(n: Int): A = new A(n)
  implicit def aToB[A1 <% A](a: A1): B = new B(a.n, a.n)
  implicit def bToC[B1 <% B](b: B1): C = new C(b.m, b.n, b.m + b.n)
  implicit def dToC[D1 <% D](d: D1): C = new C(d.m, d.n, d.m + d.n)  //Added by me

  println(5.total) //Ambiguous implicit conversion error
  println(new A(5).total) //Ambiguous implicit conversion error
  println(new B(5, 5).total) //Ambiguous implicit conversion error
  println(new C(5, 5, 10).total) 
}

I don’t understand how both bToC and dToC are possible conversion functions for say println(new B(5, 5).total).

  • 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-06-08T21:14:01+00:00Added an answer on June 8, 2026 at 9:14 pm

    View bounds obviously get translated to an extra implicit function parameter. So both bToC and dToC get translated to [T](x: T)(implicit f: T => Something): C

    The issue being that the compiler disregards the presence/absence of implicit arguments in the ambiguity check.

    case class Foo[A](value: A)
    implicit def foo[A](x: A)(implicit ev: Any =:= String) = Foo(x)
    implicit def bar[A](x: A)(implicit ev: Any =:= Int) = Foo(x)
    1.value //Ambiguous though none are applicable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a much more short version of my code: char token[256]; unsigned int
This is pretty much the same problem i have, except with very different code:
This function is much faster than its recursive version: crossSubstrings :: String -> String
Here are the steps I've followed - pretty much this: http://www.youtube.com/watch?v=cFNtD098Bbk&feature=player_embedded Create new Tab
This might be a simple one, but since I don't have much knowledge about
This feels like it should be pretty simple, but not much seems to be
this pretty much is the thing. When in tinymce I press anything that is
Important : Please see this very much related question: Return multiple values in C++
I have done this without much effort on T-SQL, but I want to implement
I really have no idea why I'm struggling with this so much. I'm scraping

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.