@@ -1819,7 +1819,10 @@ impl<'a> Context<'a> {
1819
1819
}
1820
1820
1821
1821
pub fn generate ( & mut self , aux : & WasmBindgenAux ) -> Result < ( ) , Error > {
1822
- for ( id, export) in sorted_iter ( & aux. export_map ) {
1822
+ let mut pairs = aux. export_map . iter ( ) . collect :: < Vec < _ > > ( ) ;
1823
+ pairs. sort_by_key ( |( k, _) | * k) ;
1824
+ check_duplicated_getter_and_setter_names ( & pairs) ?;
1825
+ for ( id, export) in pairs {
1823
1826
self . generate_export ( * id, export) . with_context ( |_| {
1824
1827
format ! (
1825
1828
"failed to generate bindings for Rust export `{}`" ,
@@ -2122,6 +2125,51 @@ impl<'a> Context<'a> {
2122
2125
}
2123
2126
}
2124
2127
2128
+ fn check_duplicated_getter_and_setter_names (
2129
+ exports : & [ ( & ExportId , & AuxExport ) ] ,
2130
+ ) -> Result < ( ) , Error > {
2131
+ let verify_exports =
2132
+ |first_class, first_field, second_class, second_field| -> Result < ( ) , Error > {
2133
+ let both_are_in_the_same_class = first_class == second_class;
2134
+ let both_are_referencing_the_same_field = first_field == second_field;
2135
+ if both_are_in_the_same_class && both_are_referencing_the_same_field {
2136
+ bail ! ( format!(
2137
+ "There can be only one getter/setter definition for `{}` in `{}`" ,
2138
+ first_field, first_class
2139
+ ) ) ;
2140
+ }
2141
+ Ok ( ( ) )
2142
+ } ;
2143
+ for ( idx, ( _, first_export) ) in exports. iter ( ) . enumerate ( ) {
2144
+ for ( _, second_export) in exports. iter ( ) . skip ( idx + 1 ) {
2145
+ match ( & first_export. kind , & second_export. kind ) {
2146
+ (
2147
+ AuxExportKind :: Getter {
2148
+ class : first_class,
2149
+ field : first_field,
2150
+ } ,
2151
+ AuxExportKind :: Getter {
2152
+ class : second_class,
2153
+ field : second_field,
2154
+ } ,
2155
+ ) => verify_exports ( first_class, first_field, second_class, second_field) ?,
2156
+ (
2157
+ AuxExportKind :: Setter {
2158
+ class : first_class,
2159
+ field : first_field,
2160
+ } ,
2161
+ AuxExportKind :: Setter {
2162
+ class : second_class,
2163
+ field : second_field,
2164
+ } ,
2165
+ ) => verify_exports ( first_class, first_field, second_class, second_field) ?,
2166
+ _ => { }
2167
+ }
2168
+ }
2169
+ }
2170
+ Ok ( ( ) )
2171
+ }
2172
+
2125
2173
fn generate_identifier ( name : & str , used_names : & mut HashMap < String , usize > ) -> String {
2126
2174
let cnt = used_names. entry ( name. to_string ( ) ) . or_insert ( 0 ) ;
2127
2175
* cnt += 1 ;
0 commit comments