scalafix icon indicating copy to clipboard operation
scalafix copied to clipboard

error fix :remove unsed

Open He-Pin opened this issue 7 years ago • 9 comments

before :

    private var upstreamFailed: OptionVal[Throwable] = OptionVal.None

after

    OptionVal.None

source :akka.stream.impl.fusing.ActorGraphInterpreter.ActorOutputBoundary

He-Pin avatar Dec 01 '18 16:12 He-Pin

image

He-Pin avatar Dec 01 '18 16:12 He-Pin

@hepin1989, looks like this behavior is intentional (see tests: input / output). The reason is that the the ~LHS~ RHS of a val/var definition may contain side effects. Thus, removing the entire line could change the behavior of the program. However, if the ~LHS~ RHS is a literal, then the rule does remove the entire thing.

marcelocenerine avatar Dec 02 '18 16:12 marcelocenerine

@marcelocenerine after you removed that ,Akka did not compile:)

He-Pin avatar Dec 02 '18 16:12 He-Pin

@hepin1989 what is the resulting compile error?

We can probably remove the right-hand side if it only references vals. We can try to reproduce what the compiler does

olafurpg avatar Dec 02 '18 17:12 olafurpg

sorry, I meant RHS in my previous comment.

marcelocenerine avatar Dec 02 '18 17:12 marcelocenerine

The following causes a compiler error:

  • Input:
  private val opt: Option[String] = None
  private val num: Integer = { println("foo"); 1 }
  • Output:
  None
  { println("foo"); 1 }
None.type does not take parameters
[error]   { println("foo"); 1 }
[error]   ^

marcelocenerine avatar Dec 02 '18 17:12 marcelocenerine

Aah yes :) that is a good test case! Thank you @marcelocenerine

olafurpg avatar Dec 02 '18 17:12 olafurpg

@olafurpg could not find the symbol.

He-Pin avatar Dec 02 '18 19:12 He-Pin

@olafurpg I only make use of scalafix for remove the unused import now.the problem presents when I use the default settings.

He-Pin avatar Dec 02 '18 19:12 He-Pin