Why does the compiler care if it really is a function?

I would like to understand if there is anything else that requires this form to be disallowed other than a rule in the current compiler?

protocol Test {
  func bar()
}

extension Test {
  var bar: () -> Void {
    return { }
  }
}

struct T : Test {
  let bar: () -> Void = {}
}
error: type 'T' does not conform to protocol 'Test'
struct T : Test {
       ^
note: candidate is not a function
  let bar: () -> Void = {}
      ^

note: candidate is not a function
  var bar: () -> Void {
      ^

note: protocol requires function 'bar()' with type '() -> ()'; do you want to add a stub?
  func bar()

Especially when we finally get support for compound names, this would be a very handy thing.

4 Likes

It has been mentioned a few times previously on these forums that things like this could/should be supported. I don't think there's any theoretical reason why they aren't supported currently, just a limitation of the current implementation.

1 Like