migueldeicaza / SwiftGodot

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

Conflict with custom Variant type when using @Callable #450

Closed Stiivi closed 2 months ago

Stiivi commented 3 months ago

When a custom Variant type exists, it conflicts with the Godot Variant when declaring a @Callable function.

I have a code where an imported package contains its own Variant type. Normally one would just prefix it with the package name (MyPackage.Variant) to remove ambiguity.

The following code snippet will offend the compiler:

import SwiftGodot

enum Variant {
    case int(Int)
    case string(String)
}

@Godot
class VariantConflictNode: Node {
    @Callable
    public func doSomething() {
        // do nothing
    }
}

The errors:

/var/folders/_c/_nk3n3wn3sz_h2vrr17q95200000gn/T/swift-generated-sources/@__swiftmacro_15VariantConflict0aB4Node5GodotfMm_.swift:10:120 Cannot use instance member '_mproxy_doSomething' within property initializer; property initializers run before 'self' is available
/var/folders/_c/_nk3n3wn3sz_h2vrr17q95200000gn/T/swift-generated-sources/@__swiftmacro_15VariantConflict0aB4Node5GodotfMm_.swift:10:140 Cannot convert value of type '([Variant]) -> Variant?' to expected argument type '(VariantConflictNode) -> ([Variant]) -> Variant?'
migueldeicaza commented 2 months ago

Thank you for your pull request!