The code below is correctly parsed by the static analyzer:
class FooBar {
var bar: Self
init(bar: Self) {
self.bar = bar
}
}
generating a meaningful warning:
`'Self' is only available in a protocol or as the result of a method in a class; did you mean 'FooBar'?
However, wrapping Self
in Optional
or in implicitly unwrapped Optional
, like in the example below:
class FooBar {
var foo: Self!
var bar: Self?
}
generates an internal error:
An internal error occured. Source editor functionality is limited.
In addition, it makes the the frontend compiler crash with a Segmentation fault: 11
.
Of course it shouldn't be used this way, but nevertheless I suppose it is not an intended behaviour.
swift --version
Apple Swift version 5.1.2 (swiftlang-1100.0.278 clang-1100.0.33.9)
Target: x86_64-apple-darwin19.0.0
Thanks for having a look.