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

%init of groups not compatible with ternary operators #50

Closed
Nosskirneh opened this issue Dec 20, 2019 · 5 comments
Closed

%init of groups not compatible with ternary operators #50

Nosskirneh opened this issue Dec 20, 2019 · 5 comments

Comments

@Nosskirneh
Copy link

It would make sense to write the snippet

if (%c(SBHomeScreenBackdropView))
    %init(SwitcherBackdrop_iOS12);
else
    %init(SwitcherBackdrop_iOS11);

as a ternary statement,

%c(SBHomeScreenBackdropView) ? %init(SwitcherBackdrop_iOS12) : %init(SwitcherBackdrop_iOS11);

but that results in errors.

==> Compiling Tweak.xm (arm64)…
Tweak.xm:804:61: error: expected expression
    _logos_static_class_lookup$SBHomeScreenBackdropView() ? {Class _logos_class$SwitcherBackdrop_iOS12$...
                                                            ^
Tweak.xm:804:61: error: expected ':'
    _logos_static_class_lookup$SBHomeScreenBackdropView() ? {Class _logos_class$SwitcherBackdrop_iOS12$...
                                                            ^
                                                            : 
Tweak.xm:804:59: note: to match this '?'
    _logos_static_class_lookup$SBHomeScreenBackdropView() ? {Class _logos_class$SwitcherBackdrop_iOS12$...
                                                          ^
Tweak.xm:804:61: error: expected expression
    _logos_static_class_lookup$SBHomeScreenBackdropView() ? {Class _logos_class$SwitcherBackdrop_iOS12$...
                                                            ^
3 errors generated.

It seems like Logos outputs a mix between a normal if statement and a ternary operator.

@kirb
Copy link
Member

kirb commented Dec 20, 2019

I don’t believe this is possible without restructuring how %init is implemented. It would involve us splitting out the generated code you’re seeing there into its own inline function. That may be worth it anyway though, not just for this specific edge case but just to make the generated code slightly cleaner?

@Nosskirneh
Copy link
Author

I see. I wished I could help more, but I've never touched Perl.

@uroboro
Copy link
Member

uroboro commented Dec 20, 2019

This is somewhat related to item 2 of #5.

Can you try doing this in the mean time?

%c(SBHomeScreenBackdropView) ? (%init(SwitcherBackdrop_iOS12)) : (%init(SwitcherBackdrop_iOS11));

@Nosskirneh
Copy link
Author

@uroboro Yes, that works fine, thank you!

@uroboro
Copy link
Member

uroboro commented Dec 25, 2019

While it does indeed work, I don’t believe this is a good application of the ternary operator. I won’t be adding any specific support for this usage.

@uroboro uroboro closed this as completed Dec 25, 2019
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

3 participants