Unified Symbol Resolution giving non-unique resolution of variables

Hi all,

I’m trying to use the USRs provided by SourceKit and have noticed that they are not unique within a file for variables. For example with the file:

for x in [1, 2, 3] {
  print(x)
}

for x in [4, 5, 6] { // This `x` has the same USR as that on line 1 and 2
  print(x)
}

Is this the intended behaviour? I am using the following command to retrieve the USR:

./sourcekitd-test -req=cursor -pos=line:col filenamefilename

I notice that Xcode manages to recognise which symbols are related. Is there another tool it uses to do this?

1 Like

Looks like a bug which we should fix.
Although we are already tracking this internally, could you file a JIRA issue?

Not really. Refactoring > Rename on x in the first print(x) tries to rename all four x s :sweat:

Thanks for your response @rintaro, could you add the Radar link: https://bugs.swift.org/browse/SR-7205

RE Xcode, the ‘edit all in scope’ feature seems to cope with this. Would you happen to know how that tool is working? I might just be missing some SourceKit feature

I added the radar link. Edit-all-in-scope works because it is built on top of the AST directly and checks for pointer equality of Decls being referenced, not for the USR. That approach only works because it’s is limited to a single file.