-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Conversation
0c2c7ec
to
c16f1ce
Compare
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] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tp.typeSymbolDirect.isAliasType
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
c16f1ce
to
f223a7e
Compare
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.
this seems to have been forgotten about. can you suggest a reviewer? |
@SethTisue I believe the community that wants the fix will step up to review it! I believe in the community! |
There was a problem hiding this 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 = |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this 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} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
I need another session to exercise the last commit. While debugging the underlying issue, I realized I know nothing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏅
And we're back under 2,100 issues in scala/bug! |
🙀 |
I'll create a few new issues to address @SethTisue 's nits. Is there a "nit" label? |
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 |
I won't rest until all the code is used. |
no child (in any abstract syntax tree) left behind |
"I speak for the trees." - The Lorax. |
Looks like this regressed for a local val captured in a CBN closure:
nok:
ok:
|
thanks @som-snytt ... (Actually this might have been a bug in my compiler plugin...) |
* 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
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 ofC
.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