MS 문서인데
This rule helps in catching functional bugs introduced from the following scenarios:
- Accidental typing mistakes, where the user accidentally typed the same constant value for multiple members.
- Copy paste mistakes, where the user copied an existing member definition, then renamed the member but forgot to change the value.
- Merge resolution from multiple branches, where a new member was added with a different name but the same value in different branches.
이 규칙은 다음과 같은 시나리오에서 발생하는 기능적 버그를 포착하는 데 도움이 됩니다:
사용자가 실수로 여러 멤버에 동일한 상수 값을 입력한 타이핑 오류.
기존 멤버 정의를 복사한 후 멤버 이름을 변경했지만 값 변경을 잊은 복사 붙여넣기 오류.
서로 다른 브랜치에서 이름은 다르지만 동일한 값을 가진 새 멤버가 추가된 병합 해결 시 발생하는 오류.
https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1069
ms 가 c++ 에서는 그냥 둔걸
c# 에서는 잡기로 결정한걸까win api 는 레거시 취급인가
-------------------
댓글에 스위프트에 관해봤는데 얘네는 경고 수준이 아니고 걍 컴파일 오류내고 막아놓음
<stdin>:3:15: error: raw value for enum case is not unique
1 | enum Status: Int {
2 | case success = 200
| `- note: raw value previously used here
3 | case ok = 200 // 값 중복
| `- error: raw value for enum case is not unique
4 | case failure = 500
5 | }
그래서 static 으로 별칭 만들어야됨
이건 php 에서도 따라할 수있음.
enum ShowWindowCmd: int
{
case HIDE = 0;
case SHOWNORMAL = 1;
case SHOWMINIMIZED = 2;
case MAXIMIZE = 3;
// 별칭 (Win API의 중복된 상수 이름 처리)
public const NORMAL = self::SHOWNORMAL;
// SW_MAXIMIZE도 3
public const SHOWMAXIMIZED = self::MAXIMIZE;
}
print ( ShowWindowCmd::NORMAL->value);
뭐 경고는 그냥 끄고 쓸수있지 완전히 막아둔건 아니라 다행.
모 언어는 완전히 막아놔서 후... 욕먹겠지
정답 swift
enum E { Field1 = 1, AnotherNameForField1 = Field1, // This is fine } 이런식으로라도 허용하던지 뭔 생각인지 모르겠는데
아 위에 스위프트도 enum 유일 값 막아놨다고 해서보니까임마들 swift 따라한거 같다.enum SomeEnum { case SomeLengthyCaseName // Workaround: Use a static constant as an "alias" static let SLCN = SomeEnum.SomeLengthyCaseName }print(SomeEnum.SLCN);스위프트 별칭 예시PHP 에서 따라 해보면
@피치(175.197) 댓글 왜이러지 본문 수정할게.