conflicting_type_variable_and_container 진단: type parameter와 클래스 이름이 겹치면 안 돼요

conflicting_type_variable_and_container 진단: type parameter와 클래스 이름이 겹치면 안 돼요

Dart 분석기가 내보내는 conflicting_type_variable_and_container 진단은, type parameter(타입 파라미터)의 이름이 그 type parameter를 선언한 클래스·mixin·extension(또는 enum, extension type)의 이름과 같을 때 알려주는 컴파일 타임 진단이에요. 같은 이름을 두 곳에서 쓰면 어느 쪽을 가리키는지 헷갈리니까, 분석기가 충돌을 잡아주는 거예요.

출처: conflicting_type_variable_and_container

본문

설명

분석기는 class, mixin, extension 선언이 자기 자신과 같은 이름의 type parameter를 선언할 때 이 진단을 만들어요. 클래스뿐 아니라 enum이나 extension type에서도 같은 규칙이 적용돼요.

예시

다음 코드는 type parameter C가 그 type parameter가 속한 클래스 C와 같은 이름이기 때문에 이 진단이 나와요.

class C<C> {}

흔한 해결 방법

type parameter 또는 class, mixin, extension 중 하나의 이름을 바꾸면 돼요.

class C<T> {}

더 알아보기