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

Combination of ternary operator and as? results in formatting error #163

Open
ijaureguialzo opened this issue Mar 31, 2017 · 4 comments
Open
Labels

Comments

@ijaureguialzo
Copy link
Contributor

ijaureguialzo commented Mar 31, 2017

Hello, when I format this block of code in Xcode 8.3 and Swimat 1.3.3 extension:

nombre = valores["nombre"] as? String
descripcion = valores["descripcion"] as? String
fecha_entrada = firebase ? Date(timeIntervalSince1970: valores["fecha_entrada"] as? Double ?? 0) : valores["fecha_entrada"] as? Date
fecha_salida = firebase ? Date(timeIntervalSince1970: valores["fecha_salida"] as? Double ?? 0) : valores["fecha_salida"] as? Date
noches = firebase ? valores["noches"] as? Int : Int((valores["noches"] as? Double) ?? 0)
coste = firebase ? Coste(firebase: valores["coste"] as! [String: Any?]) : valores["coste"] as? Coste

I get this output and the compilation breaks:

nombre = valores["nombre"] as? String
descripcion = valores["descripcion"] as? String
fecha_entrada = firebase ? Date(timeIntervalSince1970: valores["fecha_entrada"] as? Double ?? 0) : valores["fecha_entrada"] as? Date
fecha_salida = firebase ? Date(timeIntervalSince1970: valores["fecha_salida"] as? Double ?? 0) : valores["fecha_salida"] as? Date
noches = firebase ? valores["noches"] as ? Int : Int((valores["noches"] as? Double) ?? 0)
                                        ^--- extra space, it shouldn't be there
coste = firebase ? Coste(firebase: valores["coste"] as! [String: Any?]) : valores["coste"] as? Coste

Otherwise, thank you for this awesome tool.

@Jintin Jintin added the bug label Apr 1, 2017
@Jintin
Copy link
Owner

Jintin commented Apr 1, 2017

The parser is mismatch as ? Int : Int as a ternary.
You may add a parentheses to distinct the code first.

noches = firebase ? (valores["noches"] as? Int) : Int((valores["noches"] as? Double) ?? 0)

We'll update status after we fix the bug.
Thank you for your report, really help!!!

@ijaureguialzo
Copy link
Contributor Author

Parentheses did the trick. Thanks for the tip.

@adammenges
Copy link

Any updates here?

@ijaureguialzo
Copy link
Contributor Author

Any updates here?

Just tested with latest Swimat 1.6.2 in Xcode 10.2.1 and the bug is still present.

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

No branches or pull requests

3 participants