Handling divide by zero

I bet the ultimate reason is CGFloat being a separate type and all the sleight of hand needed for it to co-play with doubles.

func test(angle: Angle) {
    let a: CGFloat = 0
    CGPoint(x: a + cos(angle.radians), y: a + cos(angle.radians))
    // Ambiguous use of 'cos'
}

Change the above a little bit one way or another – and it compiles fine.

Filed: FB21792467

1 Like

I feel like there’s a lot of little gotchas waiting for someone to find the right combo of stuff, what with all the various wrappers, call backs to Obj-C, funky protocol shenanigans…

That it works as well as it does says something positive about the people involved.

Could you post the reports on Open Feedback Assistant?

1 Like

For what it's worth, I can reproduce a crash with 6.2, but it no longer crashes for me with the latest 6.3 snapshot, or a compiler I built myself from main.

Thank you for your contribution to the test suite ;-) Sema: Add regression test for fixed crasher by slavapestov · Pull Request #86864 · swiftlang/swift · GitHub

5 Likes

File type .swift not supported? Really?

#761

1 Like

The saga gets weirder:

In trying to narrow down the problem, I decided to remove a style configuration.

In the example I sent to Apple, there is this code:

//Cosecant Line indicator
      Path { path in
        path.move(to: pt(qdt.qx * -20, 0))
        // DIV BY ZERO
        path.addLine(to: pt(qdt.qx * -20, qdt.qy * sH/cos(angle.radians)))
      }
      .stroke(Color.orange,  style: dashStyle)
      .transformEffect(.init(1, 0, 0, -1, ctr.x, ctr.y))

I removed the “style: dashStyle” part of the stroke call, and suddenly it works.

Or if I put that back, and change the starting angle to be something other than tau*3.0/4.0 or tau/4.0, no crash.

See FB21792467: Kill The Window Server with MATH · Issue #761 · feedback-assistant/reports · GitHub for the full example.

Thanks for the additional investigation. I’ve made sure the WindowServer team is aware of your report.

4 Likes