@@ -1924,20 +1924,12 @@ struct Accessors {
19241924}
19251925
19261926fn custom_type_accessors ( constructors : & [ TypeValueConstructor ] ) -> Result < Accessors , Error > {
1927- let arguments = get_compatible_record_fields ( constructors) ;
1928-
1929- let mut shared_accessors = HashMap :: with_capacity ( arguments. len ( ) ) ;
1930-
1931- for ( index, label, type_) in arguments {
1932- let _ = shared_accessors. insert (
1933- label. clone ( ) ,
1934- RecordAccessor {
1935- index : index as u64 ,
1936- label : label. clone ( ) ,
1937- type_ : type_. clone ( ) ,
1938- documentation : None ,
1939- } ,
1940- ) ;
1927+ let accessors = get_compatible_record_fields ( constructors) ;
1928+
1929+ let mut shared_accessors = HashMap :: with_capacity ( accessors. len ( ) ) ;
1930+
1931+ for accessor in accessors {
1932+ let _ = shared_accessors. insert ( accessor. label . clone ( ) , accessor) ;
19411933 }
19421934
19431935 let mut variant_specific_accessors: Vec < HashMap < EcoString , RecordAccessor > > =
@@ -1972,9 +1964,7 @@ fn custom_type_accessors(constructors: &[TypeValueConstructor]) -> Result<Access
19721964
19731965/// Returns the fields that have the same label and type across all variants of
19741966/// the given type.
1975- fn get_compatible_record_fields (
1976- constructors : & [ TypeValueConstructor ] ,
1977- ) -> Vec < ( usize , & EcoString , & Arc < Type > ) > {
1967+ fn get_compatible_record_fields ( constructors : & [ TypeValueConstructor ] ) -> Vec < RecordAccessor > {
19781968 let mut compatible = vec ! [ ] ;
19791969
19801970 let first = match constructors. first ( ) {
@@ -1989,6 +1979,8 @@ fn get_compatible_record_fields(
19891979 None => continue ' next_argument,
19901980 } ;
19911981
1982+ let mut documentation = first_parameter. documentation . clone ( ) ;
1983+
19921984 // Check each variant to see if they have an field in the same position
19931985 // with the same label and the same type
19941986 for constructor in constructors. iter ( ) . skip ( 1 ) {
@@ -2011,12 +2003,22 @@ fn get_compatible_record_fields(
20112003 if !parameter. type_ . same_as ( & first_parameter. type_ ) {
20122004 continue ' next_argument;
20132005 }
2006+
2007+ // If there is more than one variant, we can't show documentation
2008+ // as we do not know which field it is.
2009+ documentation = None ;
20142010 }
20152011
20162012 // The previous loop did not find any incompatible fields in the other
20172013 // variants so this field is compatible across variants and we should
20182014 // generate an accessor for it.
2019- compatible. push ( ( index, first_label, & first_parameter. type_ ) )
2015+
2016+ compatible. push ( RecordAccessor {
2017+ index : index as u64 ,
2018+ label : first_label. clone ( ) ,
2019+ type_ : first_parameter. type_ . clone ( ) ,
2020+ documentation,
2021+ } )
20202022 }
20212023
20222024 compatible
0 commit comments