IBDecodable / IBLinter

A linter tool for Interface Builder
MIT License
948 stars 42 forks source link

Incorrect warning: duplicate element id #170

Closed wata closed 3 years ago

wata commented 3 years ago

IBlinter says SignIn.storyboard:0:0: warning: duplicate element id 9SU-qi-UFm. But in fact, there is only one element whose id is 9SU-qi-UFm . Is this the expected behavior?

Version: 0.4.26 Using: Homebrew and CocoaPods - same result for both .iblinter.yml:

enabled_rules:
  - misplaced
  - view_as_device
  - image_resources
excluded:
  - Pods
view_as_device_rule:
  device_id: retina5_9

Search Results for9SU-qi-UFm :

I have tried DuplicateIDRuleTests with the latest version of the source code, but it seems to be failing.

Test Suite 'DuplicateIDRuleTests' started at 2021-05-11 16:55:32.057
Test Case '-[IBLinterKitTest.DuplicateIDRuleTests testDuplicateId]' started.
/Users/wata/tmp/IBLinter/Tests/IBLinterKitTest/Rules/DuplicateIDRuleTests.swift:20: error: -[IBLinterKitTest.DuplicateIDRuleTests testDuplicateId] : XCTAssertEqual failed: ("5") is not equal to ("2")
/Users/wata/tmp/IBLinter/Tests/IBLinterKitTest/Rules/DuplicateIDRuleTests.swift:22: error: -[IBLinterKitTest.DuplicateIDRuleTests testDuplicateId] : XCTAssertEqual failed: ("["duplicate element id fullscreen", "duplicate element id iN0-l3-epB", "duplicate element id aEU-56-OK8", "duplicate element id fullscreen", "duplicate element id fullscreen"]") is not equal to ("["duplicate element id iN0-l3-epB", "duplicate element id aEU-56-OK8"]")
Test Case '-[IBLinterKitTest.DuplicateIDRuleTests testDuplicateId]' failed (0.772 seconds).
Test Suite 'DuplicateIDRuleTests' failed at 2021-05-11 16:55:32.829.
     Executed 1 test, with 2 failures (0 unexpected) in 0.772 (0.772) seconds
phimage commented 3 years ago

I launch the DuplicateIDRuleTests and no issue for me (Xcode 12.4)

wata commented 3 years ago

Thanks for checking. It's still a failure for me (Xcode 12.5)

スクリーンショット 2021-05-12 13 43 30
mt-hodaka commented 3 years ago

I’m having same issue and get same result as https://github.com/IBDecodable/IBLinter/issues/170#issuecomment-839429672

kateinoigakukun commented 3 years ago

Sorry for my slow response 🙇 Hmm, I couldn't reproduce the test failure in my local environment (w/Xcode12.5).

@wata Could you share your storyboard file facing this issue?

phimage commented 3 years ago

I test again, Xcode 12.5, IBDecodable version to 0.4.0 or 0.4.2 and no issue

wata commented 3 years ago

Thanks for your response. This is the actual file. SignIn.storyboard.zip

kateinoigakukun commented 3 years ago

@wata Thank you! However I couldn't reproduce the incorrect warning... 😢

What I tried is below. I tried this for master revision and the latest distributed version.

$ ls -a
.iblinter.yml
SignIn.storyboard
$ cat .iblinter.yml
enabled_rules:
  - misplaced
  - view_as_device
  - image_resources
excluded:
  - Pods
view_as_device_rule:
  device_id: retina5_9

$ iblinter version
0.4.26
$ iblinter
/private/var/folders/br/7sr_p7cj7v549x_gtkb33df00000gp/T/tmp.ImklW2ND/SignIn.storyboard:0:0: error: appIcon_blue not found
wata commented 3 years ago

My result:

$ ls -a
.iblinter.yml
SignIn.storyboard

$ cat .iblinter.yml
enabled_rules:
  - misplaced
  - view_as_device
  - image_resources
excluded:
  - Pods
view_as_device_rule:
  device_id: retina5_9

$ iblinter version
0.4.26

$ iblinter
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id iYo-8I-qsd
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id 7jp-cj-Jfa
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id E8n-kU-Q5C
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id L4O-JP-FdO
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id Pnf-U7-Bf2
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id h6f-C9-KfF
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id nLy-az-dV5
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id oWg-9E-n1j
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id vQt-en-xID
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id Nua-db-AEm
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id JQk-rB-6c4
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id ugH-V1-KiJ
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id DBz-aR-sRp
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id OJa-3Q-x62
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id 4qb-fh-kEd
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id vUP-Il-T7s
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id IfF-Ux-ccf
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id aUY-ad-dXj
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id L3f-4j-PFL
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id 8fl-6F-IT8
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id 8tB-gl-Bzn
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id TtQ-0E-1RQ
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id Y9A-8a-Q6E
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id cnK-2q-oAm
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id gxV-NN-gNj
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id 9SU-qi-UFm
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id 94x-Bh-O82
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id iYo-8I-qsd
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id 7jp-cj-Jfa
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id E8n-kU-Q5C
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id L4O-JP-FdO
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id Pnf-U7-Bf2
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id h6f-C9-KfF
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id nLy-az-dV5
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id oWg-9E-n1j
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id vQt-en-xID
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id Nua-db-AEm
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id JQk-rB-6c4
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id ugH-V1-KiJ
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id DBz-aR-sRp
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id OJa-3Q-x62
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id 4qb-fh-kEd
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id vUP-Il-T7s
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id IfF-Ux-ccf
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id aUY-ad-dXj
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id L3f-4j-PFL
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id 8fl-6F-IT8
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id 8tB-gl-Bzn
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id TtQ-0E-1RQ
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id Y9A-8a-Q6E
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id cnK-2q-oAm
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id gxV-NN-gNj
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id 9SU-qi-UFm
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id ar7-62-iKJ
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id iYo-8I-qsd
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id 7jp-cj-Jfa
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id E8n-kU-Q5C
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id L4O-JP-FdO
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id Pnf-U7-Bf2
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id h6f-C9-KfF
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id nLy-az-dV5
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id oWg-9E-n1j
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id vQt-en-xID
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id Nua-db-AEm
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id JQk-rB-6c4
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id ugH-V1-KiJ
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id DBz-aR-sRp
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id OJa-3Q-x62
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id 4qb-fh-kEd
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id vUP-Il-T7s
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id IfF-Ux-ccf
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id aUY-ad-dXj
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id L3f-4j-PFL
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id 8fl-6F-IT8
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id 8tB-gl-Bzn
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id TtQ-0E-1RQ
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id Y9A-8a-Q6E
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id cnK-2q-oAm
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id gxV-NN-gNj
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id 9SU-qi-UFm
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: warning: duplicate element id retina5_9
/Users/wata/tmp/2021-05-24/SignIn.storyboard:0:0: error: appIcon_blue not found
kateinoigakukun commented 3 years ago

@wata OK, I could reproduce this problem with Docker. (yeah, but it's not still reproduced on my macOS 😅 )

I'll investigate this more. Thanks for your report!

FROM swift:5.4.0

WORKDIR /Workspace
RUN git clone https://github.com/IBDecodable/IBLinter.git .
RUN swift build
RUN swift test

BTW could you tell me your OS version? In different versions of macOS, Swift uses different runtime, so it may be related. My macOS is 11.2.3 (20D91).

wata commented 3 years ago

Thank you for investigating. My macOS is 11.3 (20E232).

kateinoigakukun commented 3 years ago

I got the reason for this problem.

Context of Swift changes

Swift 5.4 has a new dynamic-cast implementation rewritten from 5.3's one. This re-implementation includes refactoring and bug fixes, so there are some different behavior from 5.3. The difference is described in here

According to the document, SR-1999 is fixed from Swift 5.4.

And the new implementation is shipped as a part of the Swift runtime library in macOS11.3.

SR-1999: Cannot cast Any contents to a protocol type

protocol P {}
class Foo: P {}
let optionalFoo: Foo? = Foo()
let any: Any = optionalFoo
// Swift 5.3: Prints "false"
// Specification: prints "true"
print(any as? P)

IBLinter implementation

We have a part that depends on the incorrect cast behavior of SR-1999 in Swift 5.3. https://github.com/IBDecodable/IBDecodable/blob/4cce9b9e864ee924be62d45b6d971218c90bba52/Sources/IBProtocol.swift#L239-L250

Even compiling the code with Swift 5.3 compiler, the new cast implementation reveals our wrong implementation on macOS11.3 because Swift uses the runtime library of not compiler-toolchain's one but the running OS's one.

This is why I couldn't reproduce this issue on macOS 11.2.3, and your macOS 11.3 reveals this.

I'll fix this issue this week.

phimage commented 3 years ago

well done

PR on IBDecodable merged