Skip to content

Lint infer-any for any-kinded#11053

Merged
lrytz merged 1 commit intoscala:2.13.xfrom
som-snytt:issue/12044-infer-any-kind
Jun 16, 2025
Merged

Lint infer-any for any-kinded#11053
lrytz merged 1 commit intoscala:2.13.xfrom
som-snytt:issue/12044-infer-any-kind

Conversation

@som-snytt
Copy link
Copy Markdown
Contributor

@som-snytt som-snytt commented May 6, 2025

-Xlint:infer-any warns if a type parameter is inferred as Any. With this commit, it warns if a higher-kinded type parameter is inferred to be Any or Nothing, which is also permitted but may be unexpected.

As usual, the lint can be selectively turned off: -Xlint:_,-infer-any or silenced:

-Wconf:cat=lint-infer-any&msg=kind-polymorphic:s

or locally in source

@nowarn("cat=lint-infer-any&msg=kind-polymorphic")

Motivating examples in the tests or the ticket, or the previous PR and its ticket. Note that Scala 3 doesn't have the same limitations for typechecking. The lint warns about a limitation in Scala 2.

See scala/bug#13128 for follow-up discussion.

Fixes scala/bug#12044

via #4401 which after ten years is ready to be uncorked.

@scala-jenkins scala-jenkins added this to the 2.13.17 milestone May 6, 2025
@lrytz
Copy link
Copy Markdown
Member

lrytz commented May 6, 2025

Looks good 👍

@som-snytt som-snytt marked this pull request as ready for review May 6, 2025 15:50
@lrytz lrytz merged commit fc2c8a7 into scala:2.13.x Jun 16, 2025
3 checks passed
@som-snytt som-snytt deleted the issue/12044-infer-any-kind branch June 16, 2025 18:34
@xuwei-k
Copy link
Copy Markdown
Contributor

xuwei-k commented Oct 1, 2025

$ scala -Xlint:infer-any
Welcome to Scala 2.13.17 (OpenJDK 64-Bit Server VM, Java 21.0.8).
Type in expressions for evaluation. Or try :help.

scala> def a[F[_]](x: Int) = x
def a[F[_]](x: Int): Int

scala> a(2)
       ^
       warning: a type was inferred to be kind-polymorphic `Nothing` to conform to `F[_]`
val res0: Int = 2

Is this expect warning? -Xlint:infer-any also report kind-polymorphic Nothing 🤔

@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Oct 7, 2025
@SethTisue
Copy link
Copy Markdown
Member

SethTisue commented Oct 7, 2025

I'm adding this to the 2.13.17 release notes.

@som-snytt you might attempt to improve the PR title and description, since it seems people are landing here.

@som-snytt
Copy link
Copy Markdown
Contributor Author

@SethTisue thanks, I made it into the release notes! for all the wrong reasons.

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

Labels

release-notes worth highlighting in next release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implicit conversion never applied but influences type inference

5 participants