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

Saturn magnitude is still buggy in some cases #76

Open
alex-vasenin opened this issue Jan 2, 2018 · 3 comments
Open

Saturn magnitude is still buggy in some cases #76

alex-vasenin opened this issue Jan 2, 2018 · 3 comments

Comments

@alex-vasenin
Copy link
Contributor

Saturn magnitude is still buggy in some cases:

    let jd = JulianDay(year: 2018, month: 1, day: 1) // Could be any date
    let jupiter = Jupiter(julianDay: jd)
    let saturn = Saturn(julianDay: jd)
    let uranus = Uranus(julianDay: jd)
    let neptune = Neptune(julianDay: jd)
    let gasGiants = [jupiter, saturn, uranus, neptune]
    print(saturn.magnitude.value) // Prints 0.479, as expected
    print(gasGiants[1].magnitude.value) // Prints nan !!!

This is one of the very few cases where Swift language itself falls short. Saturn's object is both Planet and Saturn. Planet has it's own magnitude as default implementation of IlluminatedFraction protocol. Saturn has it's own magnitude as computed property. Due to static dispatch Swift calls wrong implementation for magnitude in some cases. More info in SR-103.

@onekiloparsec
Copy link
Owner

Thanks Alexander, you're really up-to-date with these issues I have a hard time to follow. I remember wondering whether a "filling-empty-space" default implementation would be a good idea or not. It is not. I am focused on other things right now. If you have an idea on how to get around this problem... well, of course, I'm sure you'll submit it here. Thanks again!

@onekiloparsec
Copy link
Owner

onekiloparsec commented Feb 1, 2019

Just checked right now, and this is not yet fixed. Damn.

I would like to keep the default implementation. The solution I see for now is to switch from a var to a func. But this will break APIs.

Oups, no. Funcs won't work either, according to https://bugs.swift.org/browse/SR-103

@onekiloparsec
Copy link
Owner

print((gasGiants[1] as! Saturn).magnitude.value) works, but this is not satisfactory.

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

No branches or pull requests

2 participants