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

Refactor impl Default generation #1446

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

pbor
Copy link
Contributor

@pbor pbor commented Feb 26, 2023

Move the detection of a default constructor function in the analysis. Move the logic about using Object::new into object.

@pbor
Copy link
Contributor Author

pbor commented Feb 26, 2023

I know a gir rework is ongoing, so I am not sure if refactoring PRs makes sense.

The reason for this is to tackle gtk-rs/gtk-rs-core#975 by adding a new generate_default = false flag to Gir.toml, but before adding it I figured I would submit the refactoring

@pbor
Copy link
Contributor Author

pbor commented Feb 26, 2023

gtk3 fails because it has

impl Default for RadioButton {
    fn default() -> Self {
        Self::new()
    }
}

which is now generated... on the one hand I guess it is a good thing we can drop manual code, on the other it is not clear to me why this was not happening before :)

let name = &analysis.name;
if let Some(func) = analysis.default_constructor() {
general::declare_default(w, env, name, func)
} else if has_builder_properties(&analysis.builder_properties) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why with this patch RadioButton etc get picked up is because before we were falling back to object::new only if there was a new() function, but it did not have 0 params.

That seems rather odd and with the new code I did not get any false positive in core and gtk3

Move the detection of a default constructor function in the analysis.
Move the logic about using Object::new into object.
// For now we only look for new() with no params
&& f.name == "new"
&& f.parameters.rust_parameters.is_empty()
// Cannot generate Default implementation for Option<>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also do the same for Result?

@bilelmoussaoui
Copy link
Member

Would be nice to land this. But it needs PRs in at least 2 out of gtk-rs-core/gstreamer-rs/gtk4-rs with the resulting changes.

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

Successfully merging this pull request may close these issues.

None yet

2 participants