Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declaration order breaks implicit resolution in subclass #10220

Closed
scabug opened this issue Mar 7, 2017 · 2 comments
Closed

Declaration order breaks implicit resolution in subclass #10220

scabug opened this issue Mar 7, 2017 · 2 comments

Comments

@scabug
Copy link

scabug commented Mar 7, 2017

I have seen a number of implicit resolution issues that have to do with declaration order. But they all seem to occur in fairly esoteric examples. I have what I think is a very normal example:

class B extends A { implicitly[Int] }
class A { implicit val i = 3 }

error: could not find implicit value for parameter e: Int
       class B extends A { implicitly[Int] }

It works in the reverse order:

class A { implicit val i = 3 }
class B extends A { implicitly[Int] }

A funny thing is, if you try to work around it by bringing the implicit into scope manually, you get an error because you have two implicits:

class B extends A { val x = { implicit val j = i; implicitly[Int] } }
class A { implicit val i = 3 }

error: ambiguous implicit values:
 both value i in class A of type => Int
 and value j of type Int
 match expected type Int
       class B extends A { val x = { implicit val j = i; implicitly[Int] } }
                                                                   ^

But if you delete the implicit val j = i line then it cannot find the implicit.

@scabug
Copy link
Author

scabug commented Mar 7, 2017

Imported From: https://issues.scala-lang.org/browse/SI-10220?orig=1
Reporter: Daniel Darabos (darabos)
Affected Versions: 2.11.6, 2.11.8, 2.12.1
Duplicates #8697

@scabug
Copy link
Author

scabug commented Mar 7, 2017

@som-snytt said:
Isn't this just the requirement that implicits defined later in the source file must have an explicit type annotation.

class B extends A { implicitly[Int] }
class A { implicit val i: Int = 3 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant