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

Check Any-typed if/match in toString lint#11074

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

Open
som-snytt wants to merge1 commit intoscala:2.13.x
base:2.13.x
Choose a base branch
Loading
fromsom-snytt:issue/13107-tostring-lint

Conversation

som-snytt
Copy link
Contributor

Fixesscala/bug#13107

Since interpolated expressions have an expected typeAny,if andmatch expressions areAny-typed.

Before warning about them, check whether the "arms" or "branches" ("else" or "case") conform toString.

@scala-jenkinsscala-jenkins added this to the2.13.17 milestoneJun 13, 2025
@som-snytt
Copy link
ContributorAuthor

Position of diagnostic forf needs tweak? Currently it's at the CC conversion char, or where the CC would fall.

if (linting && !(arg.tpe =:= definitions.StringTpe))
def warn(msg: String) = runReporting.warning(arg.pos, msg, WFlagTostringInterpolated, c.internal.enclosingOwner)
def stringlyBranches = arg match {
case If(_, thenp, elsep) => thenp.tpe <:< definitions.StringTpe && elsep.tpe <:< definitions.StringTpe
Copy link
Member

@lrytzlrytzJun 16, 2025
edited
Loading

Choose a reason for hiding this comment

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

non-unit primitives should be allowed

scala>deff(b:Boolean)=s"b:${if (b)1else0}"^warning: interpolation uses toStringdeff(b:Boolean):String

Copy link
Member

Choose a reason for hiding this comment

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

Also nesting..

scala>deff(x:Any)=s"r:${ xmatch {cases:String=> s;case _=>if (x==null)"n"else"s" } }"^warning: interpolation uses toString

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Thanks I guess!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@lrytzlrytzlrytz left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
2.13.17
Development

Successfully merging this pull request may close these issues.

-Wtostring-interpolated warns on an if expression of type String
3 participants
@som-snytt@lrytz@scala-jenkins

[8]ページ先頭

©2009-2025 Movatter.jp