Skip to content

New linter option : -Xlint:type-parameter-shadow #17613

Closed
@schuetzcarl

Description

@schuetzcarl

For the scope of my Bachelor Project supervised by @anatoliykmetyuk,
we planned to add an equivalent lint warning as the -Xlint:type-parameter-shadow of Scala 2.

It would warn when a local type parameter shadows a type already defined in the scope :

object Example:
	class B:
		type T = Int
		trait D
		def foobar[D](in: D) = in.toString // method parameter shadows type from trait D
		type MySeq[D] = Seq[D] // type member's parameter shadows type from trait D
		
		// class parameter shadows the declared type T
		class Foo[T](t: T):
			import scala.collection.immutable.{List => List1}
			def bar[T](w: T) = w.toString // A type parameter shadows another type parameter
			def bari[List](w: T) = w.toString // No warning due to explicit renaming

		// even deeply nested... Warn for type List already defined in package scala
		class C[M[List[_]]]
		type E[M[List[_]]] = Int
		def foo[N[M[List[_]]]] = ???

		// ...but not between type parameters in the same list
		class F[A, M[L[A]]]         // no warning
		type G[A, M[L[A]]] = Int    // no warning
		def bar[A, N[M[L[A]]]] = ??? // no warning

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:reportingError reporting including formatting, implicit suggestions, etcitype:enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions