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

ExplicitImplicitTypes: false negatives for class/object vals #505

Open
ncreep opened this issue Mar 7, 2021 · 0 comments
Open

ExplicitImplicitTypes: false negatives for class/object vals #505

ncreep opened this issue Mar 7, 2021 · 0 comments

Comments

@ncreep
Copy link

ncreep commented Mar 7, 2021

Hi,

When the ExplicitImplicitTypes wart is applied to a val that's defined in class/object, it fails to trigger.

For example:

test("can't declare implicit vals inside object without a type ascription") {
  val result = WartTestTraverser(ExplicitImplicitTypes) {
    object Foo {
      implicit val foo = 5
    }
  }
  assertError(result)("implicit definitions must have an explicit type ascription")
}

This test fails. It will also fail if object is replaced with class.
On the other hand, if the val is replaced with def the test passes.

Here's the tree that's being sent to the wart:

object Foo extends scala.AnyRef {                         
  def <init>(): Foo.type = {                              
    Foo.super.<init>();                                   
    ()                                                    
  };                                                      
  private[this] val foo: Int = 5;                         
  implicit <stable> <accessor> def foo: Int = Foo.this.foo
}                                                         

The only thing here that's marked implicit is no longer a val and it's also an <accessor>. As a result, it fails the isSynthetic check:

Option(t.symbol).map(s => s.isSynthetic || s.isImplementationArtifact || (s.isTerm && s.asTerm.isAccessor)).getOrElse(false)

Would removing the s.isTerm && s.asTerm.isAccessor bit in this case be a valid solution?
Any pointers as to how this can be fixed would be most welcome.

Thanks

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

No branches or pull requests

1 participant