Support for array.reduce() in WebAssembly targets (and op_Addition generally)?

array
collections
runtime

(Jolyon Direnko-Smith) #1

Taking some tentative first steps with Swift and have quickly run into some difficulties/questions. I am attempting some real basic collection code (still learning Swift) and find that this does not compile:

let ints = [1, 2, 3]
let sum = ints.reduce(0, +)

This complains about unknown identifier op_Addition

Changing line #2 to the following compiles and runs as expected with a .net target:

let sum = ints.reduce(0) { $0 + $1 }

However, with a WebAssembly target although I get the same error for the (0, +) incantation, the second form also does not compile, this time complaining No overloaded method reduce(::) with 2 parameters on type Array<Int64>.

I had thought collections were “intrinsics” so am wondering what the state of Silver is w.r.t. the Swift language / runtime specification ? Are these bugs or expected results of design choices made to accommodate cross/multi-platform target considerations in the Elements context ?

Elements 10.0.0.2275 / Visual Studio 2015


(Carlo Kok) #3

I fixed the 'wasm" part of this.

I’ll log a separate issue for the + operator.

For now as a temporary workaround I suggest the anonymous method you had in your original post.


(RemObjects) #4

Thanks, logged as bugs://80168


(Jolyon Direnko-Smith) #5

Thanks Carlo. Just to clarify, the anon method approach doesn’t work for wasm so isn’t really a work around. I had to go the long way around:

let ints = [1, 2, 3]
var sumOfInts = 0;  for i in ints { sumOfInts += i }

Bleurgh. :face_vomiting:


(Carlo Kok) #6

I did fix it for webassembly. Will be in Friday’s beta


(Jolyon Direnko-Smith) #7

Aha, cool! Thanks for clarifying. :slight_smile: