Skip to content

Observe some -Xlint recommendations#6806

Merged
lrytz merged 4 commits intoscala:2.13.xfrom
som-snytt:topic/imports-used
Jun 19, 2018
Merged

Observe some -Xlint recommendations#6806
lrytz merged 4 commits intoscala:2.13.xfrom
som-snytt:topic/imports-used

Conversation

@som-snytt
Copy link
Contributor

Not all unused things are removed outright.

@scala-jenkins scala-jenkins added this to the 2.13.0-M5 milestone Jun 15, 2018
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.

I think we can remove unused code in general, the only exception I spotted is the check methods in ChampHashSet/Map, these probably make sense to keep in comments.


def printWriter() = new PrintWriter(outputStream(), true)
def bufferedReader(implicit codec: Codec) = new BufferedReader(new InputStreamReader(inputStream()))
def bufferedReader(implicit codec: Codec) = new BufferedReader(new InputStreamReader(inputStream(), codec.decoder))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A potential bug!

},
fork in run := true,
//scalacOptions += "-Xlint:-nullary-override,-by-name-right-associative,-inaccessible,_",
//scalacOptions ++= Seq("-Xmaxerrs", "5", "-Xmaxwarns", "5"),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

placeholders.

val mods2 = toPreTyperModifiers(mods1, ddef.symbol)
ValDef(mods2, name1, tpt0, extractRhs(rhs0))
}
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

First, do no harm.

val treeStrings = symMap(sym) map { t =>
"%10s: %s".format(t.shortClass, t)
}
val treeStrings = symMap(sym).map(t => s"${t.shortClass}%10s: $t")
Copy link
Contributor Author

@som-snytt som-snytt Jun 15, 2018

Choose a reason for hiding this comment

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

For a moment, I forgot the s interpolator. Luckily, -Xlint told me.

Actually, -Xlint complained about :+ on L182. Still need to follow up.

in.bp = runtimeAnnotStart
val numAnnots = u2
var i = 0
val i = 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not obvious whether it's a cut/paste bug.

Copy link
Member

Choose a reason for hiding this comment

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

This is an oversight, i should be incremented in the loop. #6816

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted to var.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You said you reverted it. Maybe you inverted it.

// but for the rest of us pass in top as the expected type to avoid waste.
val pt = if (origTp <:< definitions.AnyTpe) definitions.AnyTpe else WildcardType
localTyper.typed(translated, definitions.AnyTpe) setType origTp
localTyper.typed(translated, pt) setType origTp
Copy link
Contributor Author

Choose a reason for hiding this comment

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

-Xlint would have told you that. -- Paul

import infer._

private def unit = context.unit
//private def unit = context.unit
Copy link
Contributor Author

Choose a reason for hiding this comment

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

can probably zap aliases.

}

def typedTypeSelectionQualifier(tree: Tree, pt: Type = AnyRefTpe) =
def typedTypeSelectionQualifier(tree: Tree, pt: Type /*= AnyRefTpe*/) =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

documentary default, removing unused default.

Copy link
Member

Choose a reason for hiding this comment

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

Happy to have the default removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made non-documentary.


def typedSingletonTypeTree(tree: SingletonTypeTree) = {
val refTyped = typedTypeSelectionQualifier(tree.ref, WildcardType )
val refTyped = typedTypeSelectionQualifier(tree.ref, WildcardType)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

collateral whitespace change!

object <:< {
/** If `A <: B` and `B <: A`, then `A = B` (subtyping is antisymmetric) */
def antisymm[A, B](implicit l: A <:< B, r: B <:< A): A =:= B = =:=.singleton.asInstanceOf[A =:= B]
def antisymm[A, B](implicit @deprecated("unused","shim") l: A <:< B, @deprecated("unused","shim") r: B <:< A): A =:= B = =:=.singleton.asInstanceOf[A =:= B]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made a PR to ignore these cases.

def mkRowBuilder() = ArrayBuilder.make[B](ClassTag[B](aClass.getComponentType))
val bs = new ArrayOps(asArray(xs(0))).map((x: B) => mkRowBuilder())
var j = 0
//var j = 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

safe to del.


/** A view that partitions an underlying collection into two views */
@SerialVersionUID(3L)
//@SerialVersionUID(3L)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These warnings in the build should be resolved. Also, maybe the warning should sit behind a flag. -Xlint:serial? -Ywarn-serial? -Ywarn-srsly?

*/
class Channel[A] {
class LinkedList[A] {
private class LinkedList {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we're all friends here.

*/
@deprecated("use q\"new ${sym.toType}(..$args)\" instead", "2.10.1")
private[this] final val depstr_New = "use q\"new ${sym." + "toType}(..$args)\" instead"
@deprecated(depstr_New, "2.10.1")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

implicitNotFound gets a pass, but actually all ordinary annotations? I think macros supplying constants would be OK.

/* @group TypeTags */
// This class only exists to silence MIMA complaining about a binary incompatibility.
// Only the top-level class (api.PredefTypeCreator) should be used.
@deprecated("This class only exists to silence MIMA complaining about a binary incompatibility.", since="forever")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

didn't work

super.prefixString
)
// Suppressing case class copy method which risks subverting our single point of creation.
@deprecated("Suppressing case class copy method", since="forever")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

also didn't work.

// so we still see repeated parameter types (uncurry replaces them with Seq)
val isRepeated = origSym.info.paramss.flatten.map(sym => definitions.isRepeatedParamType(sym.tpe))
val oldPs = newInfo.paramss.head
val _ = newInfo.paramss.head
Copy link
Contributor Author

Choose a reason for hiding this comment

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

wary of side effects, left it in.

package reflect.io

import scala.reflect.internal.util.Statistics
//import scala.reflect.internal.util.Statistics
Copy link
Contributor Author

Choose a reason for hiding this comment

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

deletable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually all that file is commented out.

* Run with output muted both from ILoop and from the intp reporter.
*/
private def interpretPreamble = {
private def interpretPreamble() = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

left most "parens mean side effects" alone.

@som-snytt som-snytt force-pushed the topic/imports-used branch from 8957ad7 to bb17366 Compare June 15, 2018 20:53
@som-snytt
Copy link
Contributor Author

Feedback is addressed. Hopefully will be merged before it fails to merge.

val REIFY_FREE_PREFIX: NameType = "free$"
val REIFY_FREE_THIS_SUFFIX: NameType = "$this"
val REIFY_FREE_VALUE_SUFFIX: NameType = "$value"
val REIFY_FREE_VALUE_SUFFIX: NameType = s"$$value" // looks like missing interpolator due to `value` in scopre
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, StringContext name hides the interpolator. Ironic!

@som-snytt som-snytt force-pushed the topic/imports-used branch from bb17366 to 49863d1 Compare June 17, 2018 05:53
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.

Hopefully will be merged before it fails to merge.

😢

in.bp = runtimeAnnotStart
val numAnnots = u2
var i = 0
val i = 0
Copy link
Member

Choose a reason for hiding this comment

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

This is an oversight, i should be incremented in the loop. #6816

}

def typedTypeSelectionQualifier(tree: Tree, pt: Type = AnyRefTpe) =
def typedTypeSelectionQualifier(tree: Tree, pt: Type /*= AnyRefTpe*/) =
Copy link
Member

Choose a reason for hiding this comment

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

Happy to have the default removed

@@ -351,7 +358,7 @@ trait StdNames {
val MIRROR_UNTYPED: NameType = "$m$untyped"
val REIFY_FREE_PREFIX: NameType = "free$"
val REIFY_FREE_THIS_SUFFIX: NameType = "$this"
Copy link
Member

Choose a reason for hiding this comment

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

was there no warning here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sharp eyes! I'll wonder if this isPrivateLocal when I'm fully awake.

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 need a couple more days of sleep after the national election, then I'll wonder this. Or "$this".

private class NameContext(s: String) {
def n(args: Any*): TermName = { require(args.isEmpty) ; createNameType("$" + s) }
}
private def StringContext(parts: String*) = { require(parts.size == 1) ; new NameContext(parts.head) }
Copy link
Member

Choose a reason for hiding this comment

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

👍 haven't seen this before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The puzzler guy didn't like my one-liner StringContext puzzler. :( It was too improbable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason, we aren't allowed to have fun things.

@lrytz
Copy link
Member

lrytz commented Jun 18, 2018

LGTM otherwise, let's merge quickly after the rebase.

@som-snytt som-snytt force-pushed the topic/imports-used branch from a2ddb96 to a3f941e Compare June 18, 2018 14:40
The consequence of introducing `StringContext` is
that you can't use it as one. Just rename it to
something that says it's just a name.
A few `$name` happen to look like an interpolation of
a value `name`. Avoid a lint warning by using an
interpolator. To avoid the idiom for dollar literal,
let the interpolator also add the dollar. Another
day, another dollar. Also, name it the n-terpolator.
@som-snytt som-snytt force-pushed the topic/imports-used branch from a3f941e to 8911b4b Compare June 18, 2018 21:08
@lrytz lrytz merged commit 9df13fd into scala:2.13.x Jun 19, 2018
@som-snytt
Copy link
Contributor Author

@lrytz Thanks for the review of tedious material. You make a PR better than it deserves to be!

@som-snytt som-snytt deleted the topic/imports-used branch June 19, 2018 06:22
@som-snytt
Copy link
Contributor Author

som-snytt commented Jun 20, 2018

There are no plain strings. Added f for emphasis.

[error] /Users/andrew/workspace/scala/src/compiler/scala/tools/util/SocketServer.scala:98: conversions must follow a splice; use %% for literal %, %n for newline
[error]           warn(f"Accept on port %d failed")

One could lint for format strings. Yesterday, in Java land, I added a private utility for the formatted message style my colleague prefers, formatted("{} and {}", objects...), when I happened to notice that I omitted the ted and it still compiled: the file had a static import of String.format.

Also the f-interpolator could be improved, as it's obviously a missing arg.

@som-snytt som-snytt restored the topic/imports-used branch June 26, 2020 20:49
@som-snytt som-snytt deleted the topic/imports-used branch December 19, 2020 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants