[swift-users] Lazy expression is ambiguous?

Quinn "The Eskimo!" eskimo1 at apple.com
Mon Sep 12 02:48:55 CDT 2016

On 12 Sep 2016, at 08:28, Zhao Xin <owenzx at gmail.com> wrote:

> It is not a bug. 

I disagree.

> You must explicitly specify the variable's type if you use `lazy` keyword.

No, that’s not the case in general.  For example, the following code compiles just fine.

  import Dispatch

  func queueMaker() -> DispatchQueue {
    return DispatchQueue(label: "Op", attributes: .concurrent)

  class MyClass {
    lazy var myQ = queueMaker()

Regardless, there’s two possibilities here:

A. this is a real restriction in the language, which makes the poor diagnostic bugworthy

B. this is a false restriction, which makes it bugworthy in and of itself

While I personally believe that B is the case here, that’s really besides the point; something, either A or B, should change, and hence my advice.

Share and Enjoy
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

More information about the swift-users mailing list