ios - Bug in Swift array subscript indexing? -
ios - Bug in Swift array subscript indexing? -
i've isolated swift code project can pasted playground. produces error "could not find overload '+' accepts supplied arguments" both in normal xcode editing , playground. error refers lastly (non-trivial) line.
import uikit allow points = 40 allow max = points-1 allow l = 10.0 allow deltat = 0.01 allow deltax = l/double(points) var = [double](count: points, repeatedvalue: 0.0) var b = [double](count: points, repeatedvalue: 0.0) var c = [double](count: points, repeatedvalue: 0.0) in 1..<max-1 { //let iplus1 = i+1 //let temp = 0.5*deltat/deltax c[i] = 0.5*(a[i+1] + a[i-1]) + 0.5*deltat/deltax * (b[i+1] - b[i-1]) }
if uncomment line "let iplus1..." , create next edit, swift accepts code.
{ allow iplus1 = i+1 //let temp = 0.5*deltat/deltax c[i] = 0.5*(a[iplus1] + a[i-1]) + 0.5*deltat/deltax * (b[i+1] - b[i-1]) }
if uncomment line "let temp..." , create next edit, swift 1 time again accepts code.
{ //let iplus1=i+1 allow temp = 0.5*deltat/deltax c[i] = 0.5*(a[i+1] + a[i-1]) + temp * (b[i+1] - b[i-1]) }
neither of these edits create sense me, both seemingly trivial substitutions. aware swift never implicitly typecast me. there doesn't seem implicit typecasting attempted in original code -- ints , doubles declared intended. i'm starting believe bug swift array subscript indexing.
this known swift bug: long statements generate unusual compilation errors. split line in 2 lines, such as:
c[i] = 0.5*(a[i+1] + a[i-1]) c[i] += 0.5*deltat/deltax * (b[i+1] - b[i-1])
i found out happens more 4 or 5 arithmetic operations in same line, that's not rule, number found look types - may different in other cases.
look illustration @ q&a: xcode beta 6.1 , xcode 6 gm stuck indexing weird reason , xcode 6 swift super slow typing , autocompletion (this lastly 1 causes slowness, solved in same way, root same)
ios arrays swift swift-playground subscript-operator
Comments
Post a Comment