Janiczek/elm-syntax-type-inference/1.1.1

NOTE: the latest version is 2.0.1

Elm.TypeInference.Error

Errors reported while resolving or inferring a module.

type alias Error =
{ moduleName : ModuleName
, declarationNames : List VarName
, details : ErrorDetails
}

A type inference error + location info.

= ImpossibleExpr (Node Expression)
| ImpossiblePattern (Node Pattern)
| ImpossibleType TypeAnnotation
| ImpossibleDocsType Type
| MissingModuleName
| ModuleNotFound
| VarNotFound
{ usedIn : ModuleName
, varName : VarName
}
| AmbiguousName
{ usedIn : ModuleName
, varName : VarName
, possibleModules : List ModuleName
}
| AmbiguousModuleOwner
{ moduleName : String
, possiblePackages : List String
}
| TypeMismatch Type Type
| InfiniteType Type Type
| ConstraintMismatch Type Type

Types of errors:

  • ImpossibleExpr, ImpossiblePattern and ImpossibleType: for hand-crafted elm-syntax Files with nonsensical data, like a function call without arguments or a 4-tuple. You should never be able to reach these when using elm-syntax's parser on real Elm files.

  • ImpossibleDocsType: Similar but for hand-crafted docs.json. Real docs.json files emitted by the Elm compiler should never produce these.

  • MissingModuleName: Raised when Elm.TypeInference.project is called with a Dict key [].

  • ModuleNotFound: Raised when Elm.TypeInference.inferModule is called with module that's not part of the indexed Project.

  • VarNotFound:

    module Main exposing (foo)
    
    
    foo =
        bar
    
    
    --> VarNotFound
    --    { usedIn = [ "Main" ]
    --    , varName = "bar"
    --    }
  • AmbiguousName:

    module Main exposing (foo)
    
    
    import A exposing (thing)
    import B exposing (thing)
    
    
    foo =
        thing
    
    
    --> AmbiguousName
    --    { usedIn = [ "Main" ]
    --    , varName = "thing"
    --    , possibleModules = [ [ "A" ], [ "B" ] ]
    --    }
  • AmbiguousModuleOwner:

    Raised when two direct dependencies expose a module of the same name, eg. mdgriffith/elm-ui and mdgriffith/style-elements (both expose Element):

    module Main exposing (foo)
    
    
    import Element
    
    
    foo _ =
        Element.text "hi"
    
    
    --> AmbiguousModuleOwner
    --    { moduleName = "Element"
    --    , possiblePackages =
    --        [ "mdgriffith/elm-ui"
    --        , "mdgriffith/style-elements"
    --        ]
    --    }
  • TypeMismatch:

    module Main exposing (foo)
    
    
    foo : Int
    foo =
        "abc"
    
    
    --> TypeMismatch Type.Int Type.String
  • InfiniteType:

    module Main exposing (foo)
    
    
    foo x =
        x x
    
    
    --> InfiniteType
    --    (Type.TypeVar "a")
    --    (Type.Function
    --      { from = Type.TypeVar "a"
    --      , to = Type.TypeVar "b"
    --      }
    --    )
  • ConstraintMismatch:

    module Main exposing (foo)
    
    
    foo x =
        x + "a"
    
    
    --> ConstraintMismatch
    --    (Type.TypeVar "number")
    --    Type.String
toString : Error -> String

Render an error for diagnostic output.