Proposal: When a type mismatch is inside a record, print where. · Issue #4005 · purescript/purescript · GitHub
Skip to content

Proposal: When a type mismatch is inside a record, print where. #4005

Open

Description

@reactormonk

Summary

If there is a type mismatch when trying to unify two records, e.g.

{ x: "foo" }

and

{ x: 3 }

the compiler will mention it couldn't match String with Int, but it won't say which label it's under.

Motivation

Less searching required to figure out where exactly the mismatch lies.

Proposal

On error messages which refer to anything inside a label, also mention the label (possibly its full path with nesting).

Examples

Real-world example with the type mismatch being somewhere down the hatches:


  Could not match type
                
    Maybe String
                
  with type
          
    String
          

while trying to match type                                                                  
                             ( getInputProps :: { _aria :: Object String                    
                                                , autoComplete :: String                    
                                                , id :: String                              
                                                , onBlur :: EffectFn1 SyntheticEvent Unit   
                                                , onChange :: EffectFn1 SyntheticEvent Unit 
                                                , onKeyDown :: EffectFn1 SyntheticEvent Unit
                                                , value :: String                           
                                                }                                           
                             , getItemProps :: { index :: Int                               
                                               , item :: { value :: String                  
                                                         }                                  
                                               , key :: String                              
                                               , style :: CSS                               
                                               }                                            
                                               -> { _aria :: Object String                  
                                                  , id :: String                            
                                                  , role :: String                          
                                                  , style :: CSS                            
                                                  }                                         
                             , getLabelProps :: { htmlFor :: String                         
                                                , id :: String                              
                                                , ref :: Ref (Nullable Node)                
                                                }                                           
                             , getMenuProps :: { _aria :: Object String                     
                                               , id :: String                               
                                               , ref :: Ref (Nullable Node)                 
                                               , role :: String                             
                                               }                                            
                             , getRootProps :: { _aria :: Object String                     
                                               , ref :: Ref (Nullable Node)                 
                                               , role :: String                             
                                               }                                            
                             , inputValue :: Maybe String                                   
                             , selectedItem :: Maybe                                        
                                                 { value :: String                          
                                                 | t4                                       
                                                 }                                          
                             ...                                                            
                             )                                                              
                                                                                            
  with type                                                
              ( getInputProps :: Record t9                 
              , getItemProps :: { index :: Int             
                                , item :: { value :: String
                                          }                
                                , key :: String            
                                , style :: CSS             
                                }                          
                                -> Record t8               
              , getLabelProps :: Record t7                 
              , getMenuProps :: Record t6                  
              , getRootProps :: Record t5                  
              , inputValue :: String                       
              , selectedItem :: Maybe                      
                                  { value :: String        
                                  }                        
              ...                                          
              | t10                                        
              )                                            
                                                           
while solving type class constraint
                                                                                
  Prim.Row.Union ( itemToString :: Nullable t1 -> String                        
                 , items :: Array t1                                            
                 , renderChildren :: { getInputProps :: { _aria :: ...          
                                                        , autoComplete :: String
                                                        , id :: String          
                                                        , onBlur :: ...         
                                                        , onChange :: ...       
                                                        , onKeyDown :: ...      
                                                        , value :: String       
                                                        }                       
                                     , getItemProps :: ... -> ...               
                                     , getLabelProps :: { htmlFor :: String     
                                                        , id :: String          
                                                        , ref :: ...            
                                                        }                       
                                     , getMenuProps :: { _aria :: ...           
                                                       , id :: String           
                                                       , ref :: ...             
                                                       , role :: String         
                                                       }                        
                                     , getRootProps :: { _aria :: ...           
                                                       , ref :: ...             
                                                       , role :: String         
                                                       }                        
                                     , highlightedIndex :: Maybe Int            
                                     , inputValue :: Maybe String               
                                     , isOpen :: Boolean                        
                                     , selectedItem :: Maybe t1                 
                                     }                                          
                                     -> JSX                                     
                 )                                                              
                 t2                                                             
                 ( itemToString :: Nullable                                     
                                     { value :: String                          
                                     | t4                                       
                                     }                                          
                                   -> String                                    
                 , onChange :: t3 -> t3                                         
                 , renderChildren :: { getInputProps :: Record t9               
                                     , getItemProps :: ... -> ...               
                                     , getLabelProps :: Record t7               
                                     , getMenuProps :: Record t6                
                                     , getRootProps :: Record t5                
                                     , highlightedIndex :: Maybe Int            
                                     , inputValue :: String                     
                                     , isOpen :: Boolean                        
                                     , selectedItem :: Maybe ...                
                                     | t10                                      
                                     }                                          
                                     -> JSX                                     
                 )                                                              
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions