File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -143,15 +143,19 @@ julia> fieldname(Rational, 2)
143143``` 
144144""" 
145145function  fieldname (t:: DataType , i:: Integer )
146-     if  t. abstract
147-         throw (ArgumentError (" type does not have definite field names"  ))
146+     throw_not_def_field () =  throw (ArgumentError (" type does not have definite field names"  ))
147+     function  throw_field_access (t, i, n_fields)
148+         field_label =  n_fields ==  1  ?  " field"   :  " fields" 
149+         throw (ArgumentError (" Cannot access field $i  since type $t  only has $n_fields  $field_label ."  ))
148150    end 
151+     throw_need_pos_int (i) =  throw (ArgumentError (" Field numbers must be positive integers. $i  is invalid."  ))
152+ 
153+     t. abstract &&  throw_not_def_field ()
149154    names =  _fieldnames (t)
150155    n_fields =  length (names):: Int 
151-     field_label =  n_fields ==  1  ?  " field"   :  " fields" 
152-     i >  n_fields &&  throw (ArgumentError (" Cannot access field $i  since type $t  only has $n_fields  $field_label ."  ))
153-     i <  1  &&  throw (ArgumentError (" Field numbers must be positive integers. $i  is invalid."  ))
154-     return  names[i]:: Symbol 
156+     i >  n_fields &&  throw_field_access (t, i, n_fields)
157+     i <  1  &&  throw_need_pos_int (i)
158+     return  @inbounds  names[i]:: Symbol 
155159end 
156160
157161fieldname (t:: UnionAll , i:: Integer ) =  fieldname (unwrap_unionall (t), i)
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments