Janiczek/elm-syntax-type-inference/2.0.0

NOTE: the latest version is 2.0.1

Elm.TypeInference.InferError

Errors reported while resolving or inferring a module.

Errors from building a Project (Elm.TypeInference.init, Elm.TypeInference.addFile) live in Elm.TypeInference.ProjectError.

type alias InferError =
{ moduleName : ModuleName
, declarationNames : List VarName
, details : InferErrorDetails
}

A type inference error + location info.

= ImpossibleExpr (Node Expression)
| ImpossiblePattern (Node Pattern)
| ImpossibleType TypeAnnotation
| ModuleNotFound
| RangeNotFound
| VarNotFound
{ usedIn : ModuleName
, varName : VarName
}
| AmbiguousName
{ usedIn : ModuleName
, varName : VarName
, possibleModules : List ModuleName
}
| AmbiguousModuleOwner
{ moduleName : String
, possiblePackages : List String
}
| TypeNotFound
{ usedIn : ModuleName
, qualifier : ModuleName
, typeName : VarName
}
| WrongTypeArity
{ usedIn : ModuleName
, moduleName : ModuleName
, typeName : VarName
, expected : Int
, actual : Int
}
| TypeMismatch Type Type
| InfiniteType Type Type
| ConstraintMismatch Type Type
| RecursiveAlias
{ aliases :
List
{ moduleName : ModuleName
, name : VarName
}
}
| UnboundTypeVariable
{ typeName : VarName
, typeVar : VarName
}

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.

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

  • RangeNotFound: Raised when Elm.TypeInference.getType is called with a Range not corresponding to an AST node from the provided Files.

  • 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"
    --        ]
    --    }
  • TypeNotFound:

    module Main exposing (foo)
    
    
    foo : Strng -> Int
    foo _ =
        1
    
    
    --> TypeNotFound
    --    { usedIn = [ "Main" ]
    --    , qualifier = []
    --    , typeName = "Strng"
    --    }

    Qualified names need the module to be imported:

    module Main exposing (foo)
    
    
    foo : Dict.Dict String Int -> Int
    foo _ =
        1
    
    
    --> TypeNotFound
    --    { usedIn = [ "Main" ]
    --    , qualifier = [ "Dict" ]
    --    , typeName = "Dict"
    --    }

    and the type to be exposed from it:

    module Main exposing (foo)
    
    
    import Other -- `module Other exposing (publicThing)`
    
    
    foo : Other.Hidden -> Int
    foo _ =
        1
    
    
    --> TypeNotFound
    --    { usedIn = [ "Main" ]
    --    , qualifier = [ "Other" ]
    --    , typeName = "Hidden"
    --    }
  • WrongTypeArity:

    module Main exposing (foo)
    
    
    foo : Maybe Int Int -> Int
    foo _ =
        1
    
    
    --> WrongTypeArity
    --    { usedIn = [ "Main" ]
    --    , moduleName = [ "Maybe" ]
    --    , typeName = "Maybe"
    --    , expected = 1
    --    , actual = 2
    --    }
  • UnboundTypeVariable:

    module Main exposing (Foo)
    
    
    type alias Foo =
        { x : a }
    
    
    --> UnboundTypeVariable
    --    { typeName = "Foo"
    --    , typeVar = "a"
    --    }
  • 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
  • RecursiveAlias:

    module Main exposing (Comment)
    
    
    type alias Comment =
        { message : String
        , responses : List Comment
        }
    
    
    --> RecursiveAlias
    --    { aliases = [ { moduleName = [ "Main" ], name = "Comment" } ] }
toString : InferError -> String

Render an error for diagnostic output.