Backticked computed var causes weird error

Is there an issue with backtick named computed vars? I’ve never used backticks before but wanted to add a computed var named “default” so tried it out and kept getting this weird error in odd places.

The error is “Found an unexpected second identifier in variable declaration; is there an accidental break” and the error would appear on other code, sometimes even on an empty line. After some experiments it seems to only happen with computed vars...

func `default`() {}       // ok
var `default`: Int = 0    // ok
var `default`: Int { 0 }  // weird error

I’m using iPad Playgrounds which is Swift 5.10. Is this a bug or something computed vars can’t do or...?

1 Like

This seems to either be playground-specific, or a regression in 5.10. The following code works for me both in the Swift 5.9 REPL, and an online Swift 5.0 compiler:

var `default`: Int { return 0 }
1 Like

Thanks bbrk24! I hadn’t thought of checking an online compiler and tried one to see that the code runs fine. However the site didn’t say what version of Swift it used :woman_shrugging: and 5 others didn’t immediately show a version either.

But I remembered that literally minutes before I posted I noticed an update to iPad Playgrounds. Most of my testing of this issue was with Swift 5.9.2 in iPad Playgrounds, then I saw an update and got that which has Swift 5.10, and tested a couple more times to see it persisted then posted. So to me this looks most likely an issue with iPad Playgrounds so I’ll just use a func for now and let those devs know. Thanks again👍

1 Like