dotty-feature-requests icon indicating copy to clipboard operation
dotty-feature-requests copied to clipboard

Emit a warning when parsing def foo[M[_] <: List[_]](...) as it is probably not what was intended

Open smarter opened this issue 8 years ago • 2 comments

When someone write:

def foo[M[_] <: List[_]] = ???

They probably wanted to write:

def foo[M[X] <: List[X]] = ???

But were confused by the fact that _ means "higher-kinded type parameter" on the left of <: but means "wildcard" on the right. Ideally we would deprecate this syntax but until and unless that happens we could detect this sort of case and warn. (If the user intended to bound his higher-kinded type by a wildcard application he can always write: def foo[M[X] <: List[_]] or def foo[M <: [X] -> List[_]] which are clearer).

smarter avatar Dec 15 '16 16:12 smarter

Asides from the plan in #5379, it might be wonderful to have a lint rule, or if feasible a rewrite rule, for this. 🙂

dwijnand avatar Nov 05 '18 09:11 dwijnand

This seems like it should be easily doable with a scalafix linting rule.

smarter avatar Nov 07 '18 17:11 smarter