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

implicit search influenced by effect annotations #1

Open
lrytz opened this issue May 9, 2013 · 0 comments
Open

implicit search influenced by effect annotations #1

lrytz opened this issue May 9, 2013 · 0 comments

Comments

@lrytz
Copy link
Owner

lrytz commented May 9, 2013

class C

trait A {
  implicit val cOne: C
}

abstract class B(implicit cTwo: C) extends A {
  def foo = implicitly[C]
}

Without the plugin, the compiler picks cTwo. It's more specific than cOne because it's defined in a subclass.

When enabling the plugin the two implicits become ambiguous. The reason is that cOne is a reference to the getter function, which has a method type and an effect annotation. cTwo does not have a getter, so it's a direct reference to the field, and has no effect annotation:

[search] scala.this.Predef.implicitly[C] with pt=C in class B, eligible:
  cTwo: C
  cOne: => C @scala.annotation.effects.noIo

Implicit search will verify if cTwo improves over cOne, which is no longer the case. The problem is that C is not a subtype of C @noIo due to the annotation checker (which picks the top effect @io as default if there are no effect annotations).


Workaround: make cTwo a val parameter, then the implicit search will use the getter symbol which has a method type, and an effect annotation.


Fix: One way is to have a analyzer plugin hook in Implicits.improves, which invokes isStrictlyMoreSpecific. Then the plugin could remove the effect annotations from the types.

Pending test in https://github.com/lrytz/efftp/blob/master/tests/src/test/resources/scala/tools/nsc/effects/io/ClassesSuite-files/implicitsPending.scala

lrytz added a commit that referenced this issue May 9, 2013
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