Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
schuetzcarl opened this issue May 30, 2023 · 1 comment
Closed

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

schuetzcarl opened this issue May 30, 2023 · 1 comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:enhancement

Comments

@schuetzcarl
Copy link
Contributor

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
@schuetzcarl schuetzcarl added the stat:needs triage Every issue needs to have an "area" and "itype" label label May 30, 2023
@jchyb jchyb added itype:enhancement area:reporting Error reporting including formatting, implicit suggestions, etc and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 30, 2023
schuetzcarl added a commit to schuetzcarl/dotty that referenced this issue May 30, 2023
Respectively warn about :
- a private field or a class parameter that shadows a superclass field
- a local type parameter that shadows a type already in the scope

Fixes : scala#17612 and scala#17613
schuetzcarl added a commit to schuetzcarl/dotty that referenced this issue May 30, 2023
Respectively warn about :
- a private field or a class parameter that shadows a superclass field
- a local type parameter that shadows a type already in the scope

Fixes : scala#17612 and scala#17613
schuetzcarl added a commit to schuetzcarl/dotty that referenced this issue Jun 1, 2023
Respectively warn about :
- a private field or a class parameter that shadows a superclass field
- a local type parameter that shadows a type already in the scope

Fixes : scala#17612 and scala#17613
szymon-rd added a commit that referenced this issue Sep 29, 2023
Implemented two additional lint warnings for my bachelor project
supervised by @anatoliykmetyuk.

Most of the work has been done in a new `MiniPhase` class called
`CheckShadowing` and running in the same mega phase as the
`CheckUnused.PostTyper` mini phase.

They respectively warn about :
- A private field or a class parameter that shadows a super-class field.
- A type parameter that shadows a type already defined in the scope.

Some examples can be seen in #17612 and #17613.
@som-snytt
Copy link
Contributor

🎉

WojciechMazur pushed a commit that referenced this issue Jun 19, 2024
Respectively warn about :
- a private field or a class parameter that shadows a superclass field
- a local type parameter that shadows a type already in the scope

Fixes : #17612 and #17613

[Cherry-picked e5fd477]
WojciechMazur pushed a commit that referenced this issue Jun 19, 2024
Respectively warn about :
- a private field or a class parameter that shadows a superclass field
- a local type parameter that shadows a type already in the scope

Fixes : #17612 and #17613

[Cherry-picked e5fd477]
WojciechMazur pushed a commit that referenced this issue Jun 19, 2024
Respectively warn about :
- a private field or a class parameter that shadows a superclass field
- a local type parameter that shadows a type already in the scope

Fixes : #17612 and #17613

[Cherry-picked e5fd477]
WojciechMazur pushed a commit that referenced this issue Jun 19, 2024
Respectively warn about :
- a private field or a class parameter that shadows a superclass field
- a local type parameter that shadows a type already in the scope

Fixes : #17612 and #17613

[Cherry-picked e5fd477]
WojciechMazur pushed a commit that referenced this issue Jun 19, 2024
Respectively warn about :
- a private field or a class parameter that shadows a superclass field
- a local type parameter that shadows a type already in the scope

Fixes : #17612 and #17613

[Cherry-picked e5fd477]
WojciechMazur pushed a commit that referenced this issue Jun 20, 2024
Respectively warn about :
- a private field or a class parameter that shadows a superclass field
- a local type parameter that shadows a type already in the scope

Fixes : #17612 and #17613

[Cherry-picked e5fd477]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:enhancement
Projects
None yet
Development

No branches or pull requests

3 participants