Skip to content

Three bugs caught by FindBugs #4459

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

Closed
sir-wabbit opened this issue May 4, 2018 · 3 comments
Closed

Three bugs caught by FindBugs #4459

sir-wabbit opened this issue May 4, 2018 · 3 comments

Comments

@sir-wabbit
Copy link

sir-wabbit commented May 4, 2018

Using pointer equality to compare different types

val receiverIsSuper = (method.name eq sym) && enclosingClass.appliedRef.widen <:< recvWiden

on line 276 in dotty.tools.dotc.transform.TailRec

Self comparison of value with itself

  private class Set3[+Elem <: AnyRef](x0: AnyRef, x1: AnyRef, x2: AnyRef) extends SimpleIdentitySet[Elem] {
    def size = 3
    def + [E >: Elem <: AnyRef](x: E): SimpleIdentitySet[E] =
      if (contains(this)) this // <---- WAT
      else {

on line 62 of dotty.tools.dotc.util.SimpleIdentitySet

Method ignores return value

    val boundsText = domainLambdas
      " bounds = " + {
        val assocs =
          for (param <- domainParams)
          yield
            param.binder.paramNames(param.paramNum) + ": " + entryText(entry(param))
        assocs.mkString("\n")
    }

in dotty.tools.dotc.core.OrderingConstraint, line 639

@sir-wabbit sir-wabbit changed the title Two bugs caught by FindBugs Three bugs caught by FindBugs May 4, 2018
@allanrenucci
Copy link
Contributor

allanrenucci commented May 4, 2018

val receiverIsSuper = (method.name eq sym) && enclosingClass.appliedRef.widen <:< recvWiden

It should be method.name == sym.name.

However the current implementation is very inconsistent. With the fix you would get one error for:

class Foo {
  def foo = 1
}

class Test extends Foo {
  @tailrec
  final override def foo = super.foo // error
}

and two errors for:

class Foo {
  def foo() = 1
}

class Test extends Foo {
  @tailrec
  final override def foo() = super.foo() // error // error
}

@allanrenucci
Copy link
Contributor

in dotty.tools.dotc.core.OrderingConstraint, line 639

Should probably be:

    val boundsText =
      " bounds = " + {
        val assocs =
          for (param <- domainParams)
          yield
            param.binder.paramNames(param.paramNum) + ": " + entryText(entry(param))
        assocs.mkString("\n")
    }

@smarter
Copy link
Member

smarter commented Jan 26, 2019

All three bugs have been fixed.

@smarter smarter closed this as completed Jan 26, 2019
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

3 participants