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

[SR-14162] Index store does not relate static property getter used as subscript key. #56541

Open
swift-ci opened this issue Feb 7, 2021 · 6 comments
Labels
accessors Feature → declarations: Variable (property) accessors bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. expressions Feature: expressions indexing Area → source tooling: AST indexing let & var Feature: constant and variable declarations source tooling Area: IDE support, SourceKit, and other source tooling subscript expressions Feature → expressions: Subscript expressions swift 5.4 unexpected behavior Bug: Unexpected behavior or incorrect output

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Feb 7, 2021

Previous ID SR-14162
Radar rdar://problem/74102056
Original Reporter Leitch (JIRA User)
Type Bug
Environment

Swift 5.3 & 5.4 beta (Xcode 12.5 beta 1)

Additional Detail from JIRA
Votes 1
Component/s Source Tooling
Labels Bug
Assignee None
Priority Medium

md5: 7c96ce342087142383568e877034f2d5

Issue Description:

Given the following code:

enum FixtureEnum128 {
    static let someVar = ""
}

class FixtureClass128 {
    func someFunc() {
        var s: [String: Int] = [:]
        s[FixtureEnum128.someVar] = 0
    }
}

The index store does not relate the someVar getter when used as a subscript key. It does however relate the setter, which is also incorrect.

1:6 | enum/Swift | FixtureEnum128 | s:14swift_ide_test14FixtureEnum128O | Def | rel: 0
2:16 | static-property/Swift | someVar | s:14swift_ide_test14FixtureEnum128O7someVarSSvpZ | Def,RelChild | rel: 1
  RelChild | enum/Swift | FixtureEnum128 | s:14swift_ide_test14FixtureEnum128O
2:16 | static-method/acc-get/Swift | getter:someVar | s:14swift_ide_test14FixtureEnum128O7someVarSSvgZ | Def,Impl,RelChild,RelAcc | rel: 1
  RelChild,RelAcc | static-property/Swift | someVar | s:14swift_ide_test14FixtureEnum128O7someVarSSvpZ
2:16 | static-method/acc-set/Swift | setter:someVar | s:14swift_ide_test14FixtureEnum128O7someVarSSvsZ | Def,Impl,RelChild,RelAcc | rel: 1
  RelChild,RelAcc | static-property/Swift | someVar | s:14swift_ide_test14FixtureEnum128O7someVarSSvpZ
5:7 | class/Swift | FixtureClass128 | s:14swift_ide_test15FixtureClass128C | Def | rel: 0
6:10 | instance-method/Swift | someFunc() | s:14swift_ide_test15FixtureClass128C8someFuncyyF | Def,Dyn,RelChild | rel: 1
  RelChild | class/Swift | FixtureClass128 | s:14swift_ide_test15FixtureClass128C
7:17 | struct/Swift | String | s:SS | Ref,RelCont | rel: 1
  RelCont | instance-method/Swift | someFunc() | s:14swift_ide_test15FixtureClass128C8someFuncyyF
7:25 | struct/Swift | Int | s:Si | Ref,RelCont | rel: 1
  RelCont | instance-method/Swift | someFunc() | s:14swift_ide_test15FixtureClass128C8someFuncyyF
8:10 | instance-property/subscript/Swift | subscript(_:) | s:SDyq_Sgxcip | Ref,Writ,RelCont | rel: 1
  RelCont | instance-method/Swift | someFunc() | s:14swift_ide_test15FixtureClass128C8someFuncyyF
8:10 | instance-method/acc-set/Swift | setter:subscript(_:) | s:SDyq_Sgxcis | Ref,Call,Impl,RelCall,RelCont | rel: 1
  RelCall,RelCont | instance-method/Swift | someFunc() | s:14swift_ide_test15FixtureClass128C8someFuncyyF
8:11 | enum/Swift | FixtureEnum128 | s:14swift_ide_test14FixtureEnum128O | Ref,RelCont | rel: 1
  RelCont | instance-method/Swift | someFunc() | s:14swift_ide_test15FixtureClass128C8someFuncyyF
8:26 | static-property/Swift | someVar | s:14swift_ide_test14FixtureEnum128O7someVarSSvpZ | Ref,Writ,RelCont | rel: 1
  RelCont | instance-method/Swift | someFunc() | s:14swift_ide_test15FixtureClass128C8someFuncyyF
8:26 | static-method/acc-set/Swift | setter:someVar | s:14swift_ide_test14FixtureEnum128O7someVarSSvsZ | Ref,Call,Impl,RelRec,RelCall,RelCont | rel: 2
  RelCall,RelCont | instance-method/Swift | someFunc() | s:14swift_ide_test15FixtureClass128C8someFuncyyF
  RelRec | enum/Swift | FixtureEnum128 | s:14swift_ide_test14FixtureEnum128O
5:7 | constructor/Swift | init() | s:14swift_ide_test15FixtureClass128CACycfc | Def,Impl,RelChild | rel: 1
  RelChild | class/Swift | FixtureClass128 | s:14swift_ide_test15FixtureClass128C
@swift-ci
Copy link
Contributor Author

swift-ci commented Feb 7, 2021

Comment by Ian Leitch (JIRA)

/cc @benlangmuir

@benlangmuir
Copy link
Contributor

@swift-ci create

@swift-ci
Copy link
Contributor Author

Comment by Michael Thole (JIRA)

Ran into this today using Periphery to find dead code; false positive attributable to this bug. Xcode 13.

https://github.com/peripheryapp/periphery

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@keith
Copy link
Member

keith commented May 26, 2023

Looks like this is fixed in at least swift 5.7:

/*
     enum=FixtureEnum128=s:3foo14FixtureEnum128O=definition
     v  */
enum FixtureEnum128 {
    /*
               staticMethod.accessorGetter=getter:someVar=s:3foo14FixtureEnum128O7someVarSSvgZ=definition, implicit, childOf, accessorOf
               staticMethod.accessorSetter=setter:someVar=s:3foo14FixtureEnum128O7someVarSSvsZ=definition, implicit, childOf, accessorOf
               staticProperty=someVar=s:3foo14FixtureEnum128O7someVarSSvpZ=definition, childOf
               v  */
    static let someVar = ""
}

/*
      constructor=init()=s:3foo15FixtureClass128CACycfc=definition, implicit, childOf
      class=FixtureClass128=s:3foo15FixtureClass128C=definition
      v  */
class FixtureClass128 {
    /*
         instanceMethod=someFunc()=s:3foo15FixtureClass128C8someFuncyyF=definition, dynamic, childOf
         v  */
    func someFunc() {
        /*
                struct=String=s:SS=reference, containedBy
                |       struct=Int=s:Si=reference, containedBy
                v       v  */
        var s: [String: Int] = [:]
        /*
         instanceMethod.accessorSetter=setter:subscript(_:)=s:SDyq_Sgxcis=reference, call, implicit, calledBy, containedBy
         instanceProperty.swiftSubscript=subscript(_:)=s:SDyq_Sgxcip=reference, write, containedBy
         |enum=FixtureEnum128=s:3foo14FixtureEnum128O=reference, containedBy
         ||              staticMethod.accessorSetter=setter:someVar=s:3foo14FixtureEnum128O7someVarSSvsZ=reference, call, implicit, calledBy, containedBy
         ||              staticProperty=someVar=s:3foo14FixtureEnum128O7someVarSSvpZ=reference, write, containedBy
         vv              v  */
        s[FixtureEnum128.someVar] = 0
    }
}

@keith keith closed this as completed May 26, 2023
@keith keith added the indexing Area → source tooling: AST indexing label May 26, 2023
@AnthonyLatsis AnthonyLatsis added swift 5.4 source tooling Area: IDE support, SourceKit, and other source tooling unexpected behavior Bug: Unexpected behavior or incorrect output expressions Feature: expressions let & var Feature: constant and variable declarations static declarations Feature → declarations: Static declarations member expressions Feature → expressions: Member expressions subscript expressions Feature → expressions: Subscript expressions labels May 27, 2023
@AnthonyLatsis
Copy link
Collaborator

Looks like this is fixed in at least swift 5.7

@keith Is it really fixed? In your output I only see a seemingly incorrect reference to the setter, but not the getter.

@AnthonyLatsis AnthonyLatsis added accessors Feature → declarations: Variable (property) accessors and removed member expressions Feature → expressions: Member expressions static declarations Feature → declarations: Static declarations labels May 29, 2023
@keith
Copy link
Member

keith commented May 30, 2023

ah sorry I misunderstood

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessors Feature → declarations: Variable (property) accessors bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. expressions Feature: expressions indexing Area → source tooling: AST indexing let & var Feature: constant and variable declarations source tooling Area: IDE support, SourceKit, and other source tooling subscript expressions Feature → expressions: Subscript expressions swift 5.4 unexpected behavior Bug: Unexpected behavior or incorrect output
Projects
None yet
Development

No branches or pull requests

4 participants