migueldeicaza / SwiftGodot

New Godot bindings for Swift
https://migueldeicaza.github.io/SwiftGodotDocs/tutorials/swiftgodot-tutorials/
MIT License
1.01k stars 57 forks source link

Operator Overloading for `*` on `Transform2D` fallbacks inconsistently #233

Open JustinRyanH opened 8 months ago

JustinRyanH commented 8 months ago

Issue: The Transform2D * operator does not catch the type of a variable, but will handle an inline Vector2.

My suspicion is the order the * overloads are setup is causing some issue for handling the overload. there is a bug with the current version of Swift (5.9.0.128.108)

Minimum Setup:

import SwiftGodot

@Godot
class ExampleNode: Node2D {
  override func _ready() {
    if Engine.isEditorHint() { return }
    if let viewport = getViewport() {
      let size: Vector2 = Vector2(x: 0, y: 0)
      // Fails
      var first = viewport.getScreenTransform() * getGlobalTransformWithCanvas() * size
      // Works
      var second =
        viewport.getScreenTransform() * getGlobalTransformWithCanvas()
        * Vector2(x: size.x, y: size.y)
      // Works
      var canvasTransformed = viewport.getScreenTransform() * getGlobalTransformWithCanvas()
      var third = canvasTransformed * size
    }
  }
}

Result:


error: cannot convert value of type 'Vector2' to expected argument type 'Transform2D'
      viewport.getScreenTransform() * getGlobalTransformWithCanvas() * size
``
PadraigK commented 8 months ago

Boiled this down to: https://swiftfiddle.com/lo23y3354jgodbosjl35wh25m4

Seems like a Swift bug for sure.

PadraigK commented 8 months ago

I filed an issue on Swift for this, we'll see what they say! https://github.com/apple/swift/issues/69904