implicit search influenced by effect annotations #1

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

Comments

Projects
None yet
1 participant
@lrytz
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