<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p>Hi,<br>
      here are a few other ways that will compile:<br>
    </p>
    <p>af = af + [J(v:3)]<br>
      af += [J(v:4)] as [H]<br>
      af += [K(v:5)].map{ $0 as H }<br>
      af.append(K(v:6))<br>
      <br>
      It does seem that "+=" does not trigger the inference of the type
      of the array literal the way "+" does. I don't know if that's a
      bug or one of those situations where you need to help the type
      system, the error seems a little bit too cryptic though.<br>
      <br>
      It is by design that swift does not convert an array of concrete
      type to an array of protocol (it can take a long time), whereas
      single values are (like "w" and "x"). As I understand it, it's
      only because of the type inference on the array literal that its
      items are converted in the first two examples.<br>
      <br>
      Nera</p>
    <br>
    <br>
    <div class="moz-cite-prefix">Le 25/07/2016 à 23:11, Paul
      Ossenbruggen via swift-users a écrit :<br>
    </div>
    <blockquote
cite="mid:CAF1qJmh3NbXALNti7ZS3zYMvQMJZi32UNbxEVL0VQzXbn6Qvkw@mail.gmail.com"
      type="cite">
      <div dir="ltr">Thanks to matt on stack overflow, you need to
        assign it to a temporary to ensure the type is correct: 
        <div><br>
        </div>
        <div>
          <p
            style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">let
            w : H = K(v:3)</p>
          <p
            style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">let
            x : H = J(v:3)</p>
          <p
            style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">af
            += [w]</p>
          <p
            style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">af
            += [x]</p>
        </div>
        <div><br>
        </div>
        <div>Is this worthy of a bug report? Or is it inherent in the
          design of the language? </div>
        <div class="gmail_extra"><br>
          <div class="gmail_quote">On Mon, Jul 25, 2016 at 1:02 PM, Paul
            Ossenbruggen &lt;<a moz-do-not-send="true"
              href="mailto:possen@gmail.com" target="_blank">possen@gmail.com</a>&gt;
            wrote:<br>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <div dir="ltr">In swift 3.0 beta 3, I defined a fairly
                simple protocol and two structs that implement it, if I
                initialize the array when creating the objects, it
                works, but if I try to add elements I get an error:
                <div><br>
                </div>
                <div>Cannot convert value of type '[H]' to expected
                  argument type 'inout _'<br>
                  <div><br>
                  </div>
                  <div>Shouldn't this work?</div>
                  <div><br>
                  </div>
                  <div>
                    <p
style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(187,44,162)">protocol
                      H {</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"> 
                        var v : Int { get set }</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"> 
                        func hello()</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">}</p>
                    <p
style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><br>
                    </p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">struct
                      J : H {</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"> 
                        var v : Int</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"> 
                        func hello() {</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"> 
                            print("j")</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"> 
                        }</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">}</p>
                    <p
style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><br>
                    </p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">struct
                      K : H {</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"> 
                        var v : Int</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"> 
                        func hello() {</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"> 
                            print("k")</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"> 
                        }</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">}</p>
                    <p
style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><br>
                    </p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">let
                      ag:[H] =  [K(v:3), J(v:4)]</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">ag[0].hello()</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">ag[1].hello()
                      //works</p>
                    <p
style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><br>
                    </p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">var
                      af:[H] =  []</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">af
                      += [K(v:3)] // does not work</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">af
                      += [J(v:4)]</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">af[0].hello()</p>
                    <p
                      style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">af[1].hello() </p>
                  </div>
                  <div><br>
                  </div>
                </div>
              </div>
            </blockquote>
          </div>
          <br>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
swift-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:swift-users@swift.org">swift-users@swift.org</a>
<a class="moz-txt-link-freetext" href="https://lists.swift.org/mailman/listinfo/swift-users">https://lists.swift.org/mailman/listinfo/swift-users</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>