Advice on testing diagnostics and fixits

Hello,
I've recently been trying to get my toes into the compiler codebase and wanted to improve a couple of fixits that I've found annoying sometimes. My goal is to learn a bit more how the compiler works. I have the compiler setup and I've been tweaking things trough Xcode and running it against test file to see the output.

My issue is that the output for a fixit is a little cryptic and I would like to make sure that the fixit in Xcode is gonna work properly. I've tried building a toolchain and after waiting hours it failed. So before trying to build it again I wondered if there was a better solution.

  • Is there a better approach on testing diagnostic/fixits than building a toolchain for Xcode?

Thanks!

You can check whether the attached fix-it is correctly applied at a location using {{range=<TEXT>}}. For example:

class SR_9267_C2 {
  let SR_9267_prop_3: Int = { return 0 } // expected-error {{function produces expected type 'Int'; did you mean to call it with '()'?}} 
  // expected-note@-1 {{Remove '=' to make 'SR_9267_prop_3' a computed property}}{{3-6=var}}{{27-29=}}
}

If you look at the end of the note, you can see two {{range=<TEXT>}}.

  1. {{3-6=var}} means the range 3-6 (columns) is expected to be replaced with var.
  2. {{27-29=}} means the range 27-29 (columns) is expected to be removed.

You can then invoke swiftc -frontend -verify and pass the file to check whether the fix-it is correctly applied or not.

3 Likes

Thank you very much suyashsrijan!

With that tip I've been able to add the expected-error and range replacements on a test file and run it from Xcode and it worked :+1:t2: that saved me a lot of time! ^^

I will add the checks to an existing test file in the project and see if I can run them :grin:

cheers

1 Like