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

  • Home
  • SEARCH
  • 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 8005621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:16:52+00:00 2026-06-04T17:16:52+00:00

Scala seems to apply the implicit class conversion on the largest possible expression, as

  • 0

Scala seems to apply the implicit class conversion on the largest possible expression, as in the following example:

scala> class B { def b = { println("bb"); true } }
defined class B

scala> class A { def a = { println("aa"); new B } }
defined class A

scala> (new A).a.b
aa
bb
res16: Boolean = true

scala> class XXX(b: => Boolean) { def xxx = 42 }
defined class XXX

scala> implicit def toXXX(b: => Boolean) = new XXX(b)
toXXX: (b: => Boolean)XXX

scala> (new A).a.b.xxx
res18: Int = 42

I’m very happy about this fact, but my question is that which part of the SLS specifies this behavior? Why does it not evaluate (new A).a.b to true first for example, and just apply the conversion on that value?

  • 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-04T17:16:53+00:00Added an answer on June 4, 2026 at 5:16 pm

    As answered by Ryan Hendrickson on the mailing list:

    [The definition] you’re looking for is in Section 7.3, in the list of the three situations in which views are applied:

    1. In a selection e.m with e of type T, if the selector does not denote a member
      of T. In this case, a view v is searched which is applicable to e and whose result
      contains a member named m. The search proceeds as in the case of implicit
      parameters, where the implicit scope is the one of T. If such a view is found,
      the selection e.m is converted to v(e).m.

    So the compiler can only generate something that is semantically equivalent to v(e).m, and as you’ve demonstrated, when by-name parameters are involved

    val x = e
    v(x).m
    

    is not semantically equivalent to v(e).m.

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

Sidebar

Related Questions

Possible Duplicate: How can I chain implicits in Scala? Can Scala apply multiple implicit
Some things in Scala seems opaque to me such as the following when to
An implicit question to newcomers to Scala seems to be: where does the compiler
In Scala, if I define a method called apply in a class or a
Scala programmer should have known that this sort of writing : class Person{ var
In Scala, if I have a simple class as follows: val calc = actor
Does Scala have a version of Rubys' each_slice from the Array class?
It seems like the support for printing arrays is somewhat lacking in Scala. If
I installed Scala IDE for Eclipse , and it seems to be working okay.
I am playing with this example http://scala.sygneca.com/code/remoteactors to learn how remote actors work in

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.