Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong constructor in structs with computed properties #70

Closed
angelolloqui opened this issue Mar 20, 2018 · 1 comment
Closed

Wrong constructor in structs with computed properties #70

angelolloqui opened this issue Mar 20, 2018 · 1 comment

Comments

@angelolloqui
Copy link
Owner

angelolloqui commented Mar 20, 2018

When translating structs into dataclasses, the current translators converts this:

struct Rect {
    var origin = Point()
    var size = Size()

    var center: Point {
        get {
            let centerX = origin.x + (size.width / 2)
            let centerY = origin.y + (size.height / 2)
            return Point(x: centerX, y: centerY)
        }
        set(newCenter) {
            origin.x = newCenter.x - (size.width / 2)
            origin.y = newCenter.y - (size.height / 2)
        }
    }
}

into:


data class Rect(
    var origin = Point(),
    var size = Size(),
    var center: Point
        get() {
            val centerX = origin.x + (size.width / 2)
            val centerY = origin.y + (size.height / 2)
            return Point(x = centerX, y = centerY)
        }
        set(newCenter) {
            origin.x = newCenter.x - (size.width / 2)
            origin.y = newCenter.y - (size.height / 2)
        }) {}

The first 2 properties are properly placed into the constructor, but the computed one should be kept out of it, like:


data class Rect(
    var origin = Point(),
    var size = Size()) {
    var center: Point
        get() {
            val centerX = origin.x + (size.width / 2)
            val centerY = origin.y + (size.height / 2)
            return Point(x = centerX, y = centerY)
        }
        set(newCenter) {
            origin.x = newCenter.x - (size.width / 2)
            origin.y = newCenter.y - (size.height / 2)
        }
}
@angelolloqui
Copy link
Owner Author

angelolloqui commented Mar 20, 2018

Fixed with b60576f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant