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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:07:56+00:00 2026-06-01T21:07:56+00:00

Consider this case class: case class IntPrinter(implicit val i: Int) { def print()(implicit i:

  • 0

Consider this case class:

case class IntPrinter(implicit val i: Int) {
  def print()(implicit i: Int) = println(i)
}

I can instance it explicitly passing a value for the implicit argument like this:

val p = IntPrinter()(9)

I’ve been told in IRC that, from now on, the explicitly passed value will be implicitly passed to print when being called, but that’s not the case:

p.print()
 error: could not find implicit value for parameter i: Int

Am I doing something wrong or I’ve misunderstood/been given incorrect information? Is there any way to achieve this?


EDIT: as a matter of fact it works as expected if I import p._ like this:

import p._
p.print()

Which indeed prints 9.

Is this the correct behaviour? Is using import as bad idea as it sounds? How do I workaround this?

  • 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-01T21:07:58+00:00Added an answer on June 1, 2026 at 9:07 pm

    Indeed it’s the correct behaviour. implicit values are only searched in current scope and calling print outside IntPrinter means it’s not on the class scope (obviously) and the reason why I had to import it.

    The correct way to do what I wanted:

    case class IntPrinter(implicit val i: Int) {
      def print()(implicit i: Int) = println(i)
      def printProxy() = print()
    }
    

    And then calling p.printProxy behaves like I wanted it to behave (because printProxy is inside IntPrinter‘s scope.)

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

Sidebar

Related Questions

Consider this class: case class Person(val firstName: String, val lastName: String, age: Int) val
Consider the following: object Main { case class Foo(bar: Int) extends FooList { val
Consider this case: public class SomeClass { public void someMethod() { new SomeInterface() {
Consider this syntactically correct(?) pseudocode: class Event { public: virtual int getID() const =
Consider this code: import scala.xml.{Node,HasKeyValue} def domatch(x:Node): Node = { val hasBar = new
Consider the case of class which does not have a destructor and constructor explicitly
Consider this test case: class MyObject : public QObject { Q_OBJECT public: MyObject() {
Consider this case: public Class1 { public static final String ONE = ABC; public
Consider this case: dll = LoadDLL() dll->do() ... void do() { char *a =
consider this piece of scala swing code detail.reactions += { case ButtonClicked(but) => detail.contents

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.