Skip to content

Warn-unused uses type alias in nesting check #6190

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

Merged
merged 7 commits into from
Feb 22, 2018
Merged

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Nov 22, 2017

A reference from the body of a class is not a usage
of the class, but a reference to a local type alias of it
is a usage of the type alias.

Also don't warn about filter for refutable pattern.

Also classOf[C] is a usage of C.

Simplify message for a var that isn't mutated.

Fixes scala/bug#10623
Fixes scala/bug#10394
Fixes scala/bug#9058
Fixes scala/bug#10282
Fixes scala/bug#10448

@scala-jenkins scala-jenkins added this to the 2.12.5 milestone Nov 22, 2017
@som-snytt som-snytt closed this Nov 23, 2017
@som-snytt som-snytt reopened this Nov 23, 2017
for (tp <- t.tpe if !treeTypes(tp) && !currentOwner.ownerChain.contains(tp.typeSymbol)) {
tp match {
for (tp <- t.tpe if !treeTypes(tp)) {
val alias = tp.isInstanceOf[AliasTypeRef]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the best one can do?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tp.typeSymbolDirect.isAliasType?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That pulls in too much, it turns out. I tried various isNonClassType etc, so mostly I don't actually understand the API.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That pulls in too much

Can you give an example?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In constructors you see:

[log typer] ALIAS C.super.type/class scala.reflect.internal.Types$UniqueSuperType/class C/type AnyRef primary constructor C
[log typer] C.super.type referenced from primary constructor C

with the false negative for object X { private class C }. So the AnyRef is the Direct.isAliasType, defined as an alias of Object.

I guess it's sufficient to also check isLocal || isPrivate.

A reference from the body of a class is not a usage
of the class, but a reference to a local type alias of it
is a usage of the type alias.
The call has the form, `qual.withFilter(check$refutable => body)`
where the body is `{ case mypat => true }` which must always
spuriously warn about any pattern variables.
Notice ConstantType and record it under -Ywarn-unused.
Although vars have setters, it's more uniform to report
that the private var is not updated. (It's not possible
that the setter is overriding a synthetic setter for a var,
so there can be no ambiguity.)
Incremental compilation while erroring can result in unpositioned
trees.

Parser preserves the escape hatch attachment
under patdef transform.

Both casedef and valdef can test immediately if escape hatch
was requested.

Add attachment for valdefs resulting from patvardefs.

When checking for redundant unused setters, try to compare
using accessed, otherwise compare names.
@SethTisue
Copy link
Member

this seems to have been forgotten about. can you suggest a reviewer?

@som-snytt
Copy link
Contributor Author

@SethTisue I believe the community that wants the fix will step up to review it! I believe in the community!

Copy link
Contributor

@hrhino hrhino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just because you asked.

It might be cool to add the ticket references in somewhere for future retrospective capabilities.

@@ -732,11 +732,16 @@ abstract class TreeGen {
def mkPatDef(pat: Tree, rhs: Tree)(implicit fresh: FreshNameCreator): List[ValDef] =
mkPatDef(Modifiers(0), pat, rhs)

private def cpAtBoundAttachment(from: Tree, to: ValDef): to.type =
if (from.hasAttachment[AtBoundIdentifierAttachment.type]) to.updateAttachment(AtBoundIdentifierAttachment) else to
private def cpPatVarDefAttachments(from: Tree, to: ValDef): to.type =
Copy link
Contributor

@hrhino hrhino Feb 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is UNIX for copy? It seems strange that cpAtBoundAttachment only adds the attachment if from has it but cpPatVarDefAttachments unconditionally adds PatVarDefAttachment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One propagates whether the syntax was x @ _, the other adds that this is a patvar. There is doc over in TypeDiag.

I would justify cp by persistence of mk for make and similar, which are not due to a subculture. I do resist long names, and these are long.

I think I will shave my beard now and maybe go get a hair cut.

Don't add attachments when not warning.

Avoid warning when already in error.
Copy link
Member

@SethTisue SethTisue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this all looks plausible to me, but maybe one more pair of eyes on the attachments stuff.

@@ -10,7 +10,7 @@ import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.util.control.Exception.ultimately
import symtab.Flags._
import PartialFunction._
import PartialFunction.{condOpt => whenever}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seth's nit: I know, condOpt isn't the greatest name, but it's the name we have, I don't think we should indulge ourselves in arbitrary local renamings like this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know what you mean. Paulp once said those methods where the most underlooked of his contributions, and I think it's partly the names. Maybe we can fix that.

@som-snytt
Copy link
Contributor Author

I need another session to exercise the last commit. While debugging the underlying issue, I realized I know nothing.

Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏅

@hrhino
Copy link
Contributor

hrhino commented Feb 22, 2018

And we're back under 2,100 issues in scala/bug!

@lrytz
Copy link
Member

lrytz commented Feb 22, 2018

🙀

@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Feb 22, 2018
@som-snytt
Copy link
Contributor Author

I'll create a few new issues to address @SethTisue 's nits. Is there a "nit" label?

@som-snytt som-snytt deleted the issue/10623 branch February 22, 2018 17:42
@SethTisue
Copy link
Member

SethTisue commented Feb 22, 2018

very glad to see this crossing the finish line! 🎉 thanks Som, greatly appreciate your ongoing commitment to this unused warnings work, it's a real boon for code quality community-wide

@som-snytt
Copy link
Contributor Author

I won't rest until all the code is used.

@SethTisue
Copy link
Member

no child (in any abstract syntax tree) left behind

@som-snytt
Copy link
Contributor Author

"I speak for the trees." - The Lorax.

@adriaanm
Copy link
Contributor

adriaanm commented Mar 8, 2018

Looks like this regressed for a local val captured in a CBN closure:

class Test {
  def timed[T](body: => T) = body

  def run(): Boolean = {
    val grouped = List(("bla","bla"))


    val (_, _) = timed {
      for ((kind, paths) <- grouped) {
        println("")
      }
      (1, 2)
    }
    
    false
  }
}

nok:

➜  Desktop sbt 'set resolvers += "pr-integration" at "https://scala-ci.typesafe.com/artifactory/scala-integration"' 'set scalaVersion := "2.12.5-bin-56918e4"' 'set scalacOptions ++= Seq("-Xfatal-warnings", "-Xlint:unused")' compile
[info] Compiling 1 Scala source to /Users/adriaan/Desktop/target/scala-2.12/classes...
[error] /Users/adriaan/Desktop/unused_captured.scala:5: local val grouped in method run is never used
[error]     val grouped = List(("bla","bla"))
[error]         ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 2 s, completed Mar 8, 2018 11:25:25 AM

ok:

➜  Desktop sbt 'set resolvers += "pr-integration" at "https://scala-ci.typesafe.com/artifactory/scala-integration"' 'set scalaVersion := "2.12.5-bin-f78f517"' 'set scalacOptions ++= Seq("-Xfatal-warnings", "-Xlint:unused")' compile
[info] Compiling 1 Scala source to /Users/adriaan/Desktop/target/scala-2.12/classes...
[success] Total time: 3 s, completed Mar 8, 2018 11:25:49 AM

@lrytz lrytz added 2.12 and removed 2.12 labels Mar 14, 2018
@SethTisue SethTisue added release-notes worth highlighting in next release notes and removed release-notes worth highlighting in next release notes labels Mar 15, 2018
@fommil
Copy link
Contributor

fommil commented Mar 20, 2018

thanks @som-snytt ... I'm still getting false positives in synthetic methods. I don't know how to create a minimisation that doesn't depend on the scalaz-deriving compiler plugin.

(Actually this might have been a bug in my compiler plugin...)

ivanopagano added a commit to Cryptonomic/Conseil that referenced this pull request Dec 24, 2018
 * split the Conseil configurations
 * use typed objects in PlatformDiscovery and separate from
   the confguration file parsing
 * use imports to get config readers into scope
 * create custom readers for platforms
 * wrap lightbend config for the host pool in a
   configuration class
 * fix residuals compilation errors from the merge
 * upgrade pureconfig version, improving the available api
 * upgrade scala version to latest,
   which fix scala/scala#6190
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants