title: Generics of raw types (Int, Float, Double) create weird error messages
body: <p>Can someone here maybe take a look at the code and tell me what's wrong with it? I essentially try to build a couple of generic functions that operate on certain raw types like <code>Int</code>, <code>Float</code>, <code>Double</code> etc.</p>
  
  <p>Unfortunately I can't get it working properly. This is the code that works (partially):</p>
  
  <pre><code>// http://stackoverflow.com/a/24047239/2282430
  protocol SummableMultipliable: Equatable {
      func +(lhs: Self, rhs: Self) -&gt; Self
      func *(lhs: Self, rhs: Self) -&gt; Self
  }
  
  extension Double: SummableMultipliable {}
  
  func vec_dot&lt;T where T: SummableMultipliable&gt;(a : [T], b: [T]) -&gt; Double {
      assert(a.count == b.count, "vectors must be of same length")
      var s : Double = 0.0
      for var i = 0; i &lt; a.count; ++i {
          let x = (a[i] * b[i]) as Double
          s = s + x
      }
      return s
  }
  </code></pre>
  
  <p>Now when I write:</p>
  
  <pre><code> var doubleVec : [Double] = [1,2,3,4]
  
   vec_dot(doubleVec, doubleVec)
  </code></pre>
  
  <p>It returns the correct result of <code>30</code>. Ok, so far so good. Things get weird when I try to pass an array of <code>Int</code>s:</p>
  
  <pre><code> extension Int : SummableMultipliable {}
   var intVec : [Int] = [1,2,3,4]
   vec_dot(intVec, intVec)
  </code></pre>
  
  <p>Bam! Exception thrown at:</p>
  
  <pre><code> let x = (a[1] * b[1]) as Double
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>* thread #1: tid = 0x139dd0, 0x00000001018527ad libswiftCore.dylib`swift_dynamicCast + 1229, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
    * frame #0: 0x00000001018527ad libswiftCore.dylib`swift_dynamicCast + 1229
      frame #1: 0x000000010d6c3a09 $__lldb_expr248`__lldb_expr_248.vec_dot &lt;A : __lldb_expr_248.SummableMultipliable&gt;(a=Swift.Array&lt;T&gt; at 0x00007fff5e5a9648, b=Swift.Array&lt;T&gt; at 0x00007fff5e5a9640) -&gt; Swift.Double + 921 at playground248.swift:54
      frame #2: 0x000000010d6c15b0 $__lldb_expr248`top_level_code + 1456 at playground248.swift:64
      frame #3: 0x000000010d6c4561 $__lldb_expr248`main + 49 at &lt;EXPR&gt;:0
      frame #4: 0x000000010165b390 FirstTestPlayground`get_field_types__XCPAppDelegate + 160
      frame #5: 0x000000010165bea1 FirstTestPlayground`reabstraction thunk helper from @callee_owned () -&gt; (@unowned ()) to @callee_owned (@in ()) -&gt; (@out ()) + 17
      frame #6: 0x000000010165ab61 FirstTestPlayground`partial apply forwarder for reabstraction thunk helper from @callee_owned () -&gt; (@unowned ()) to @callee_owned (@in ()) -&gt; (@out ()) + 81
      frame #7: 0x000000010165bed0 FirstTestPlayground`reabstraction thunk helper from @callee_owned (@in ()) -&gt; (@out ()) to @callee_owned () -&gt; (@unowned ()) + 32
      frame #8: 0x000000010165bf07 FirstTestPlayground`reabstraction thunk helper from @callee_owned () -&gt; (@unowned ()) to @callee_unowned @objc_block () -&gt; (@unowned ()) + 39
      frame #9: 0x0000000101fedaac CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
      frame #10: 0x0000000101fe37f5 CoreFoundation`__CFRunLoopDoBlocks + 341
      frame #11: 0x0000000101fe2fb3 CoreFoundation`__CFRunLoopRun + 851
      frame #12: 0x0000000101fe29f6 CoreFoundation`CFRunLoopRunSpecific + 470
      frame #13: 0x000000010208f2b1 CoreFoundation`CFRunLoopRun + 97
      frame #14: 0x0000000101658be8 FirstTestPlayground`top_level_code + 3784
      frame #15: 0x000000010165b3ba FirstTestPlayground`main + 42
      frame #16: 0x0000000103cd9145 libdyld.dylib`start + 1
  </code></pre>
  
  <p>I tried to perform a different casting:</p>
  
  <pre><code>let x = Double(a[i] * b[1])
  </code></pre>
  
  <blockquote>
    <p><strong>Error:</strong> Could not find an overload for 'init' that accepts the supplied arguments.</p>
  </blockquote>
  
  <pre><code>let y = a[i] * b[1]
  let x = Double(y)
  </code></pre>
  
  <blockquote>
    <p><strong>Error:</strong> Cannot invoke 'init' with an argument of type 'T'.</p>
  </blockquote>
  
  <p>Next, I tried:</p>
  
  <pre><code>let y = Double(a[i]) * Double(b[1])
  let x = y
  </code></pre>
  
  <blockquote>
    <p><strong>Error:</strong> Cannot invoke '*' with an argument list of type '(Double, Double'). </p>
  </blockquote>
  
  <p>I tried out <em>many</em> more things. As soon as I try to pass <code>Int</code> as a generic type, nothing works anymore.</p>
  
  <p>Maybe I'm just missing something fundamental here or I am just too dumb to understand generic programming. In C++, I'd be done in 2 seconds.</p>