wartremover
wartremover copied to clipboard
ExplicitImplicitTypes: false negatives for class/object vals
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