- Notifications
You must be signed in to change notification settings - Fork3.1k
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
base:2.13.x
Are you sure you want to change the base?
Conversation
Position of diagnostic for |
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 |
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.
non-unit primitives should be allowed
scala>deff(b:Boolean)=s"b:${if (b)1else0}"^warning: interpolation uses toStringdeff(b:Boolean):String
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.
Also nesting..
scala>deff(x:Any)=s"r:${ xmatch {cases:String=> s;case _=>if (x==null)"n"else"s" } }"^warning: interpolation uses toString
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.
Thanks I guess!
Fixesscala/bug#13107
Since interpolated expressions have an expected type
Any
,if
andmatch
expressions areAny
-typed.Before warning about them, check whether the "arms" or "branches" ("else" or "case") conform to
String
.