Question about overlapped multiple fixits from diagnostics


I read this comment.

Please tell me about detail of it.

I first thought that it says about conflict of edit between fixits which has overlapped range of text.

But when I use xcode and click fix-it button,
diagnostics are fully regenerated immediately from code which is applied fixit.
So it doesn't seems to happen problems.

Above comment says about extra argument diagnostic and relabeling argument diagnostic.
Then I worried about missing argument and relabeling argument.

They could be overlapped if input weird source code.
For example:

[omochi@omochi-iMacPro temp]$ cat a.swift
func f(aa: Int, bbbb: Int, cc: Int, dd: Int) {}
f(dd: 1, aa: 1, bbbb: 2)
[omochi@omochi-iMacPro temp]$ swift -frontend -typecheck -fixit-all a.swift -emit-fixits-path a.remap
a.swift:2:2: error: incorrect argument labels in call (have 'dd:aa:bbbb:', expected 'aa:bbbb:cc:dd:')
f(dd: 1, aa: 1, bbbb: 2)
 ^~~     ~~     ~~~~
  aa     bbbb   cc
a.swift:2:15: error: missing argument for parameter 'cc' in call
f(dd: 1, aa: 1, bbbb: 2)
              , cc: <#Int#>
a.swift:1:6: note: 'f(aa:bbbb:cc:dd:)' declared here
func f(aa: Int, bbbb: Int, cc: Int, dd: Int) {}

I tried to which they can be applied both.

[omochi@omochi-iMacPro temp]$ cat a.remap
  "file": "a.swift",
  "offset": 50,
  "remove": 2,
  "text": "aa",
  "file": "a.swift",
  "offset": 57,
  "remove": 2,
  "text": "bbbb",
  "file": "a.swift",
  "offset": 64,
  "remove": 4,
  "text": "cc",
  "file": "a.swift",
  "offset": 62,
  "text": ", cc: <#Int#>",
[omochi@omochi-iMacPro temp]$ c-arcmt-test a.remap
[omochi@omochi-iMacPro temp]$ cat /var/folders/1v/_s33fkpj07g9y3zvdfs9cz9m0000gn/T/a.swift-2771df.swift
func f(aa: Int, bbbb: Int, cc: Int, dd: Int) {}
f(aa: 1, bbbb: 1, cc: <#Int#>, cc: 2)

Applied result looks ok syntactically.
(Semantically wrong. Because label dd doesn't exist and cc are duplicated.)

So I don't understand meaning of one fix would overwrite another.

This comment is trying to convey that re-labeling fix uses base locator at the moment, which means that there is going to be a single fix (RelabelArguments) which covers whole call so if we tried to add another fix (of a different kind) with the same locator it would be lost.

The idea behind this TODO is to make it possible for matchCallArguments to track labeling failures individually in order for diagnostics to avoid doing all the this work.

I think this comment might no longer apply to re-labeling + extra arguments, but I think if you try to remove this check there should be test failures which would make it clearer what is wrong.

1 Like

Thank you for your reply.
I got many hints for me.
I will study concept of Locator and how it works with diagnostics engine.
And try to modify code, observe results.

And thank you for teaching about TODO.
I was just concerned that there are logics which seems to be duplicated in matchCallArguments and diagnoseArgumentLabelError.

Terms of Service

Privacy Policy

Cookie Policy