Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add-Wtostring-interpolated to warn if interpolator usestoString#10776

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@som-snytt
Copy link
Contributor

@som-snyttsom-snytt commentedMay 7, 2024
edited
Loading

Adds-Wtostring-interpolated which warns if a standard interpolator usestoString to convert a value which is not string or primitive type.

-Wconf:cat=w-flag-tostring-interpolated:e to boost.

Also restores edge casef"${ "hello" }%b" which is"true" for non-boolean arg. That became an error in previous refactor, possibly intentionally. (It is arguably an obscure feature of format.) (Edit: the C.I. error reminds me that the change was to make the expected type Boolean, so that conversions work normally. That is also edge casey. Maybe it can try boolean, null, and any? Edit: yes, try non-any first, then any if allowed.)

The "default"%s is improved so that the warning position is at the interpolated element ins"$x".

Follow-up to#8654

He-Pin, lenguyenthanh, lolgab, github-dimitri-ho, and igor-ramazanov reacted with thumbs up emojilenguyenthanh, KristianLentinoCT, lolgab, jatcwang, v3xro, github-dimitri-ho, and igor-ramazanov reacted with hooray emoji
@scala-jenkinsscala-jenkins added this to the2.13.15 milestoneMay 7, 2024
@som-snyttsom-snyttforce-pushed thetopic/warn-toString-interpolated branch 2 times, most recently from6e463fb toab4a1d1CompareMay 8, 2024 06:05
@som-snytt
Copy link
ContributorAuthor

Previous feedback at wartremover is to allow at leastCharSequence and perhaps primitives with "canonical" representations (Int,Char, but notFloat,Double). What about usual formatting ofInt such as1,024?

Therefore, no accommodation is made yet here.

A future version can take a typeclass, implicit locale, etc.

@som-snyttsom-snytt marked this pull request as ready for reviewMay 8, 2024 16:59
@som-snyttsom-snyttforce-pushed thetopic/warn-toString-interpolated branch fromab4a1d1 tocbf369dCompareMay 8, 2024 17:13
@SethTisueSethTisue added the release-notesworth highlighting in next release notes labelMay 21, 2024
@som-snyttsom-snyttforce-pushed thetopic/warn-toString-interpolated branch fromcbf369d todc21f58CompareJune 16, 2024 13:05
@som-snytt
Copy link
ContributorAuthor

Added the exclusion for primitives but notCharSequence.

Dotty reflect says don't usetoString! I will forward port.

CharSequence is indeed a sequence of chars, but the implementation could have arbitrary characteristics.

StringBuilder is a close call, but arguably you shouldn't be interpolating it but building with it.

@som-snytt
Copy link
ContributorAuthor

spurious error on first commit after rebase

[info] [info] set current project to sbt_8abf1597 (in build file:/tmp/sbt_8abf1597/)[info] [error] lmcoursier.internal.shaded.coursier.error.FetchError$DownloadingArtifacts: Error fetching artifacts:[info] [error] file:///home/jenkins/.ivy2/local/org.scala-lang/scala-compiler/2.13.15-bin-SNAPSHOT/jars/scala-compiler.jar: wrong checksum: /home/jenkins/.ivy2/local/org.scala-lang/scala-compiler/2.13.15-bin-SNAPSHOT/jars/scala-compiler.jar (expected SHA-1 83c122d8bc099f9087008091b008e29b99e89b68 in /home/jenkins/.ivy2/local/org.scala-lang/scala-compiler/2.13.15-bin-SNAPSHOT/jars/scala-compiler.jar.sha1, got 87e3f962badf079fa40348f5e4ffa1c25fe6f85d)[info] [error] [info] [error] at lmcoursier.internal.shaded.coursier.Artifacts$.$anonfun$fetchArtifacts$9(Artifacts.scala:365)[info] [error] at lmcoursier.internal.shaded.coursier.util.Task$.$anonfun$flatMap$extension$1(Task.scala:14)[info] [error] at lmcoursier.internal.shaded.coursier.util.Task$.$anonfun$flatMap$extension$1$adapted(Task.scala:14)[info] [error] at lmcoursier.internal.shaded.coursier.util.Task$.wrap(Task.scala:82)[info] [error] at lmcoursier.internal.shaded.coursier.util.Task$.$anonfun$flatMap$2(Task.scala:14)[info] [error] at scala.concurrent.Future.$anonfun$flatMap$1(Future.scala:307)[info] [error] at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:51)[info] [error] at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:74)[info] [error] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)[info] [error] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)[info] [error] at java.lang.Thread.run(Thread.java:750)[info] [error] Caused by: lmcoursier.internal.shaded.coursier.cache.ArtifactError$WrongChecksum: wrong checksum: /home/jenkins/.ivy2/local/org.scala-lang/scala-compiler/2.13.15-bin-SNAPSHOT/jars/scala-compiler.jar (expected SHA-1 83c122d8bc099f9087008091b008e29b99e89b68 in /home/jenkins/.ivy2/local/org.scala-lang/scala-compiler/2.13.15-bin-SNAPSHOT/jars/scala-compiler.jar.sha1, got 87e3f962badf079fa40348f5e4ffa1c25fe6f85d)[info] [error] at lmcoursier.internal.shaded.coursier.cache.FileCache.$anonfun$validateChecksum$4(FileCache.scala:146)[info] [error] at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:659)[info] [error] at scala.util.Success.$anonfun$map$1(Try.scala:255)[info] [error] at scala.util.Success.map(Try.scala:213)[info] [error] at scala.concurrent.Future.$anonfun$map$1(Future.scala:292)[info] [error] at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:42)[info] [error] at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:74)[info] [error] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)[info] [error] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)[info] [error] at java.lang.Thread.run(Thread.java:750)[info] [error] (update) lmcoursier.internal.shaded.coursier.error.FetchError$DownloadingArtifacts: Error fetching artifacts:

then

[error] [info] waiting for lock on /home/jenkins/.ivy2/.sbt.ivy.lock to be available...[info] [info] compiling 1 Scala source to /tmp/sbt_8131f52f/macro-provider/target/classes ...[info] [error] ## Exception when compiling 1 sources to /tmp/sbt_8131f52f/macro-provider/target/classes[info] [error] java.lang.NoClassDefFoundError: scala/reflect/macros/internal/macroImpl[info] [error] scala.reflect.internal.Definitions$DefinitionsClass.MacroImplAnnotation$lzycompute(Definitions.scala:587)[info] [error] scala.reflect.internal.Definitions$DefinitionsClass.MacroImplAnnotation(Definitions.scala:587)[info] [error] scala.tools.nsc.typechecker.Macros.$anonfun$loadMacroImplBinding$1(Macros.scala:291)[info] [error] scala.collection.mutable.AnyRefMap.getOrElseUpdate(AnyRefMap.scala:169)[info] [error] scala.tools.nsc.typechecker.Macros.loadMacroImplBinding(Macros.scala:293)[info] [error] scala.tools.nsc.typechecker.Macros.loadMacroImplBinding$(Macros.scala:289)[info] [error] scala.tools.nsc.Global$$anon$6.loadMacroImplBinding(Global.scala:514)[info] [error] scala.tools.nsc.typechecker.Macros.standardIsBlackbox(Macros.scala:310)[info] [error] scala.tools.nsc.typechecker.Macros.standardIsBlackbox$(Macros.scala:308)[info] [error] scala.tools.nsc.Global$$anon$6.standardIsBlackbox(Global.scala:514)[info] [error] scala.tools.nsc.typechecker.AnalyzerPlugins$$anon$10.default(AnalyzerPlugins.scala:466)[info] [error] scala.tools.nsc.typechecker.AnalyzerPlugins$$anon$10.default(AnalyzerPlugins.scala:463)[info] [error] scala.tools.nsc.typechecker.AnalyzerPlugins.invoke(AnalyzerPlugins.scala:428)

Copy link
Member

@lrytzlrytz left a comment

Choose a reason for hiding this comment

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

LGTM otherwise! I'm not familiar with the code though.

@som-snyttsom-snyttforce-pushed thetopic/warn-toString-interpolated branch fromdc21f58 to6afc3a5CompareJune 17, 2024 18:01
@som-snytt
Copy link
ContributorAuthor

gah

[info] [info] compiling 2 Scala sources to /tmp/sbt_9b694d86/target/classes ...[info] [error] ## Exception when compiling 2 sources to /tmp/sbt_9b694d86/target/classes[info] [error] java.util.ServiceConfigurationError: xsbti.compile.CompilerInterface2: Error reading configuration file[info] [error] java.util.ServiceLoader.fail(ServiceLoader.java:232)

@som-snytt
Copy link
ContributorAuthor

/rebuild

@som-snytt
Copy link
ContributorAuthor

fool me twice

[info] [info] compiling 1 Scala source to /tmp/sbt_f26212df/target/classes ...[info] [error] ## Exception when compiling 2 sources to /tmp/sbt_f26212df/target/classes[info] [error] java.util.ServiceConfigurationError: xsbti.compile.CompilerInterface2: Error reading configuration file[info] [error] java.util.ServiceLoader.fail(ServiceLoader.java:232)

Copy link
Member

@lrytzlrytz left a comment

Choose a reason for hiding this comment

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

Nice, thank you! Let's squash before merge.

@som-snyttsom-snyttforce-pushed thetopic/warn-toString-interpolated branch fromd138e6c to1ac2451CompareJune 19, 2024 20:16
@som-snytt
Copy link
ContributorAuthor

Squashed & rebased for ✔️ (🤞 )

@som-snyttsom-snytt merged commit1bda625 intoscala:2.13.xJun 20, 2024
@som-snyttsom-snytt deleted the topic/warn-toString-interpolated branchJune 20, 2024 00:51
@SethTisueSethTisue changed the titleWarn if interpolator uses toStringAddAdds -Wtostring-interpolated to warn if interpolator usestoStringAug 22, 2024
@SethTisueSethTisue changed the titleAddAdds -Wtostring-interpolated to warn if interpolator usestoStringAdd-Wtostring-interpolated to warn if interpolator usestoStringAug 22, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@lrytzlrytzlrytz approved these changes

Assignees

No one assigned

Labels

release-notesworth highlighting in next release notes

Projects

None yet

Milestone

2.13.15

Development

Successfully merging this pull request may close these issues.

4 participants

@som-snytt@lrytz@SethTisue@scala-jenkins

[8]ページ先頭

©2009-2025 Movatter.jp