Skip to content

Commit

Permalink
Merge #840
Browse files Browse the repository at this point in the history
840: Fix unresolved enum name in bindings generator r=Bromeon a=Bromeon

Example: when using godot-rust with the VoxelTools engine module, the api.json has many nested `Result` types. In some occurrences, these identifiers are prefixed with the containing class, e.g. `VoxelStreamResult`. However, some references to these type names are not using the prefixed identifier, thus creating compile errors (see commit message for details).

This PR addresses this by prefixing other occurrences, when enums are constructed.

Co-authored-by: Jan Haller <bromeon@gmail.com>
  • Loading branch information
bors[bot] and Bromeon committed Jan 8, 2022
2 parents b2a9832 + 8270899 commit 35be953
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions bindings_generator/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use heck::ToPascalCase as _;
use super::classes::generate_enum_name;
use miniserde::Deserialize;
use proc_macro2::TokenStream;
use quote::{format_ident, quote};
use std::collections::{HashMap, HashSet};

use miniserde::Deserialize;
miniserde::make_place!(Place);

pub struct Api {
Expand Down Expand Up @@ -400,7 +400,8 @@ impl Ty {
// Enums may reference known types (above list), check if it's a known type first
let mut split = ty[5..].split("::");
let class_name = split.next().unwrap();
let name = format_ident!("{}", split.next().unwrap().to_pascal_case());
let enum_raw_name = split.next().unwrap();
let name = format_ident!("{}", generate_enum_name(class_name, enum_raw_name));
let module = format_ident!("{}", module_name_from_class_name(class_name));
// Is it a known type?
match Ty::from_src(class_name) {
Expand Down
2 changes: 1 addition & 1 deletion bindings_generator/src/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub(crate) fn generate_enums(class: &GodotClass) -> TokenStream {
}
}

fn generate_enum_name(class_name: &str, enum_name: &str) -> String {
pub(crate) fn generate_enum_name(class_name: &str, enum_name: &str) -> String {
// In order to not pollute the API with more Result types,
// rename the Result enum used by Search to SearchResult.
// to_pascal_case() is used to make the enums more rust-like.
Expand Down

0 comments on commit 35be953

Please sign in to comment.