• Kipper

    v0.12.1
  • Downloads

  • Docs

  • Playground

  • Changelog

  • Kipper

    v0.12.1
    • Downloads

    • Docs

    • Playground

    • Changelog

      • 0.11.0 /
      • Kipper API /
      • Module /
      • @kipper/core /
      • compiler
    Kipper Docs
    • next
    • latest
    • 0.11.0
    • 0.10.4
    • 0.9.2
    • Overview

    • Quickstart

    • Goals for Kipper

    • Supported platforms

    • Usage Examples

      • Overview

      • Compiler Setup

        • Overview

          • index

          • compiler

          • errors

          • logger

          • utils

          • config

          • index

          • index

        • Overview

        • new

        • run

        • compile

        • help

        • version

    • Variables

      • Overview

      • String Type

      • Number Type

      • Boolean Type

      • Void Type

      • Null Type

      • Undefined Type

      • Array Type

      • Overview

      • Arithmetic Expression

      • Assignment Expression

      • Conditional Expressions

      • Logical Expressions

      • Bitwise Expression

      • Relational Expressions

      • Convert Expression

      • F-String Expression

      • Member Access Expression

      • Function Call Expression

      • Overview

      • Expression Statement

      • If Statement

      • While Loop

      • Do-While Loop

      • For Loop

      • Compound Statement

      • Jump Statement

    • Functions

    • Comments

    • Built-in Functions

      • 0.11.0 /
      • Kipper API /
      • Module /
      • @kipper/core /
      • compiler
    • 0.11.0 /
    • Kipper API /
    • Module /
    • @kipper/core /
    • compiler

    Edit page

    Class: KipperTypeChecker

    compiler.KipperTypeChecker

    Kipper Type Checker, which asserts that type logic and cohesion is valid and throws errors in case that an invalid use of types and identifiers is detected.

    Since

    0.7.0

    Hierarchy

    • KipperSemanticsAsserter

      ↳ KipperTypeChecker

    Table of contents

    Constructors

    • constructor

    Properties

    • col
    • ctx
    • filePath
    • line
    • programCtx
    • stream

    Methods

    • assertError
    • checkMatchingTypes
    • error
    • getCheckedType
    • getTypeOfMemberAccessExpression
    • notImplementedError
    • objectLikeIsIndexableOrAccessible
    • refTargetCallable
    • setTracebackData
    • typeExists
    • validArgumentValue
    • validArithmeticExpression
    • validAssignment
    • validBitwiseExpression
    • validBracketNotationKey
    • validConditionalExpression
    • validConversion
    • validFunctionCallArguments
    • validRelationalExpression
    • validReturnCodePathsInFunctionBody
    • validReturnStatement
    • validSliceNotationKey
    • validUnaryExpression
    • validVariableDefinition
    • getTypeForAnalysis

    Constructors

    constructor

    • new KipperTypeChecker(programCtx)

    Parameters

    Name Type
    programCtx KipperProgramContext

    Overrides

    KipperSemanticsAsserter.constructor

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:75

    Properties

    col

    • Protected col: undefined | number

    Inherited from

    KipperSemanticsAsserter.col

    Defined in

    kipper/core/src/compiler/analysis/analyser/err-handler/semantics-error-handler.ts:16


    ctx

    • Protected ctx: undefined | CompilableASTNode<SemanticData, TypeData>

    Inherited from

    KipperSemanticsAsserter.ctx

    Defined in

    kipper/core/src/compiler/analysis/analyser/err-handler/semantics-error-handler.ts:17


    filePath

    • Protected filePath: undefined | string

    Inherited from

    KipperSemanticsAsserter.filePath

    Defined in

    kipper/core/src/compiler/analysis/analyser/err-handler/semantics-error-handler.ts:18


    line

    • Protected line: undefined | number

    Inherited from

    KipperSemanticsAsserter.line

    Defined in

    kipper/core/src/compiler/analysis/analyser/err-handler/semantics-error-handler.ts:15


    programCtx

    • Readonly programCtx: KipperProgramContext

    Inherited from

    KipperSemanticsAsserter.programCtx

    Defined in

    kipper/core/src/compiler/analysis/analyser/err-handler/semantics-asserter.ts:19


    stream

    • Protected stream: undefined | KipperFileStream

    Inherited from

    KipperSemanticsAsserter.stream

    Defined in

    kipper/core/src/compiler/analysis/analyser/err-handler/semantics-error-handler.ts:19

    Methods

    assertError

    ▸ Protected assertError(error, overwriteCtx?): KipperError

    Updates the given error and adds the proper traceback data, and returns it.

    Parameters

    Name Type Description
    error KipperError The error to update.
    overwriteCtx? CompilableASTNode<SemanticData, TypeData> The context to overwrite the current context with. This is used when a parent checks children semantics in order to provide the correct traceback data and errors occur in the children.

    Returns

    KipperError

    The Kipper error.

    Inherited from

    KipperSemanticsAsserter.assertError

    Defined in

    kipper/core/src/compiler/analysis/analyser/err-handler/semantics-asserter.ts:34


    checkMatchingTypes

    ▸ checkMatchingTypes(type1, type2): boolean

    Checks whether the passed types are matching.

    Since

    0.10.0

    Parameters

    Name Type Description
    type1 KipperCompilableType The first type that is given.
    type2 KipperCompilableType The second type that is given.

    Returns

    boolean

    True if the types are matching, otherwise false.

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:146


    error

    ▸ Protected error(error): KipperError

    Updates the error and adds the proper traceback data, and returns it.

    This function also automatically logs the error.

    Parameters

    Name Type Description
    error KipperError The error to update.

    Returns

    KipperError

    The Kipper error.

    Inherited from

    KipperSemanticsAsserter.error

    Defined in

    kipper/core/src/compiler/analysis/analyser/err-handler/semantics-error-handler.ts:52


    getCheckedType

    ▸ getCheckedType(type): CheckedType

    Creates a new CheckedType instance based on the passed KipperType.

    If the type is invalid, the function will still return a CheckedType, but the field isCompilable will be false and the instance WILL NOT be usable for a compilation.

    Parameters

    Name Type Description
    type UncheckedType The unchecked type to analyse.

    Returns

    CheckedType

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:113


    getTypeOfMemberAccessExpression

    ▸ getTypeOfMemberAccessExpression(memberAccess): CheckedType

    Get the type that this member access expression is accessing.

    Since

    0.10.0

    Parameters

    Name Type Description
    memberAccess MemberAccessExpression The member access expression to get the type for.

    Returns

    CheckedType

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:663


    notImplementedError

    ▸ notImplementedError(error): KipperNotImplementedError

    Modifies the metadata for a KipperNotImplementedError

    Since

    0.7.0

    Parameters

    Name Type Description
    error KipperNotImplementedError The KipperNotImplementedError instance.

    Returns

    KipperNotImplementedError

    Inherited from

    KipperSemanticsAsserter.notImplementedError

    Defined in

    kipper/core/src/compiler/analysis/analyser/err-handler/semantics-asserter.ts:55


    objectLikeIsIndexableOrAccessible

    ▸ objectLikeIsIndexableOrAccessible(objLike): void

    Checks whether the members of the passed objLike can be accessed. (As well if there are members)

    Throws

    If the object expression is not an object.

    Since

    0.10.0

    Parameters

    Name Type Description
    objLike Expression<ExpressionSemantics, ExpressionTypeSemantics, CompilableASTNode<SemanticData, TypeData>> The object-like expression to check.

    Returns

    void

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:593


    refTargetCallable

    ▸ refTargetCallable(ref): void

    Asserts that the passed ref is callable. This function will only check ScopeDeclaration instances, since built-in functions will always be callable.

    Throws

    If the passed ref is not callable.

    Since

    0.10.0

    Parameters

    Name Type Description
    ref Expression<ExpressionSemantics, ExpressionTypeSemantics, CompilableASTNode<SemanticData, TypeData>> | Reference<KipperReferenceable> The reference to check.

    Returns

    void

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:164


    setTracebackData

    ▸ setTracebackData(data): void

    Sets the traceback related metadata that will be used to create a traceback for an KipperError instance.

    In case that data.ctx is set and other fields are missing, these fields will be filled up using the data in the data.ctx AST node ctx instance.

    Since

    0.8.0

    Parameters

    Name Type Description
    data Object The traceback data that will be used to initialise an KipperError instance.
    data.col? number -
    data.ctx? CompilableASTNode<SemanticData, TypeData> -
    data.filePath? string -
    data.line? number -
    data.stream? KipperFileStream -

    Returns

    void

    Inherited from

    KipperSemanticsAsserter.setTracebackData

    Defined in

    kipper/core/src/compiler/analysis/analyser/err-handler/semantics-error-handler.ts:29


    typeExists

    ▸ typeExists(type): void

    Asserts that the passed type identifier exists.

    Since

    0.7.0

    Parameters

    Name Type Description
    type string The type to check.

    Returns

    void

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:100


    validArgumentValue

    ▸ validArgumentValue(arg, receivedType): void

    Asserts that the argument type matches the type of the argument value passed.

    Example

    call print("x"); // <-- Parameter type 'str' must match type of argument "x"

    Throws

    If the given argument type does not match the parameter type.

    Since

    0.7.0

    Parameters

    Name Type Description
    arg ParameterDeclaration | BuiltInFunctionArgument The parameter that the value was passed to.
    receivedType CheckedType The type that was received.

    Returns

    void

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:263


    validArithmeticExpression

    ▸ validArithmeticExpression(leftOp, rightOp, op): void

    Asserts that the passed type allows the arithmetic operation.

    Throws

    If the type of the left or right operand is not a number, and the operation is not a concatenation of strings.

    Since

    0.9.0

    Parameters

    Name Type Description
    leftOp Expression<ExpressionSemantics, ExpressionTypeSemantics, CompilableASTNode<SemanticData, TypeData>> The left validBracketNotationKeyoperand expression.
    rightOp Expression<ExpressionSemantics, ExpressionTypeSemantics, CompilableASTNode<SemanticData, TypeData>> The right operand expression.
    op KipperArithmeticOperator The arithmetic operation that is performed.

    Returns

    void

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:393


    validAssignment

    ▸ validAssignment(assignmentExp): void

    Asserts that the passed expression is valid and the assigned value is compatible with the identifier.

    Throws

    In case a arithmetic assignment operation is used with an invalid type.

    Throws

    If the value type can not be assigned to the identifier type.

    Since

    0.7.0

    Parameters

    Name Type Description
    assignmentExp AssignmentExpression The assignment expression to check.

    Returns

    void

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:195


    validBitwiseExpression

    ▸ validBitwiseExpression(leftOp, rightOp, op): void

    Asserts that the passed type allows the bitwise operation.

    Throws

    If the type of the left or right operand is not a number.

    Since

    0.11.0

    Parameters

    Name Type Description
    leftOp Expression<ExpressionSemantics, ExpressionTypeSemantics, CompilableASTNode<SemanticData, TypeData>> The left operand expression.
    rightOp Expression<ExpressionSemantics, ExpressionTypeSemantics, CompilableASTNode<SemanticData, TypeData>> The right operand expression.
    op KipperBitwiseOperator The bitwise operation that is performed.

    Returns

    void

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:428


    validBracketNotationKey

    ▸ validBracketNotationKey(objLike, key): void

    Ensure the passed key may be used to access the members of the passed objLike.

    Throws

    In case the key type can not be used to index the object-like expression.

    Since

    0.10.0

    Parameters

    Name Type Description
    objLike Expression<ExpressionSemantics, ExpressionTypeSemantics, CompilableASTNode<SemanticData, TypeData>> The object-like expression to check.
    key Expression<ExpressionSemantics, ExpressionTypeSemantics, CompilableASTNode<SemanticData, TypeData>> The key that accesses the members of the object-like expression.

    Returns

    void

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:614


    validConditionalExpression

    ▸ validConditionalExpression(trueBranch, falseBranch): void

    Checks whether the conditional expression is valid.

    Throws

    When the branch types are mismatching, as union types are not implemented yet.

    Since

    0.11.0

    Parameters

    Name Type Description
    trueBranch Expression<ExpressionSemantics, ExpressionTypeSemantics, CompilableASTNode<SemanticData, TypeData>> The expression which is called when the condition evaluates to true.
    falseBranch Expression<ExpressionSemantics, ExpressionTypeSemantics, CompilableASTNode<SemanticData, TypeData>> The expression which is called when the condition evaluates to false.

    Returns

    void

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:721


    validConversion

    ▸ validConversion(operand, targetType): void

    Asserts that the type conversion for the operand is valid.

    Throws

    If the conversion is invalid/impossible.

    Since

    0.8.0

    Parameters

    Name Type Description
    operand Expression<ExpressionSemantics, ExpressionTypeSemantics, CompilableASTNode<SemanticData, TypeData>> The expression to convert.
    targetType CheckedType The type to convert to.

    Returns

    void

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:450


    validFunctionCallArguments

    ▸ validFunctionCallArguments(func, args): void

    Asserts that the passed function arguments are valid.

    Throws

    If the amount of arguments is invalid e.g. too many or too few.

    Throws

    If any given argument type does not match the required parameter type.

    Since

    0.7.0

    Parameters

    Name Type Description
    func KipperReferenceableFunction The function that is called.
    args Expression<ExpressionSemantics, ExpressionTypeSemantics, CompilableASTNode<SemanticData, TypeData>>[] The arguments for the call expression.

    Returns

    void

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:298


    validRelationalExpression

    ▸ validRelationalExpression(exp): void

    Asserts that the passed relational expression is valid.

    Throws

    If the value types can not be compared.

    Since

    0.9.0

    Parameters

    Name Type Description
    exp RelationalExpression The relational expression to check.

    Returns

    void

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:318


    validReturnCodePathsInFunctionBody

    ▸ validReturnCodePathsInFunctionBody(func): void

    Ensures that the body of the func has valid return statements and all code paths return a value.

    Requires func.typeSemantics to be set.

    Throws

    If not all code paths return a value.

    Since

    0.10.0

    Parameters

    Name Type Description
    func LambdaExpression | FunctionDeclaration The function where the body should be checked.

    Returns

    void

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:510


    validReturnStatement

    ▸ validReturnStatement(returnStatement): void

    Asserts that the passed return statement is valid.

    Throws

    If the type of the return value does not match the return type of the function.

    Since

    0.10.0

    Parameters

    Name Type Description
    returnStatement ReturnStatement The return statement to check.

    Returns

    void

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:478


    validSliceNotationKey

    ▸ validSliceNotationKey(objLike, key): void

    Ensure the passed slice keys may be used to access the members of the passed objLike.

    Throws

    In case the key type can not be used to index the object-like expression.

    Since

    0.10.0

    Parameters

    Name Type Description
    objLike Expression<ExpressionSemantics, ExpressionTypeSemantics, CompilableASTNode<SemanticData, TypeData>> The object-like expression to check.
    key Object The key that accesses the members of the object-like expression.
    key.end? Expression<ExpressionSemantics, ExpressionTypeSemantics, CompilableASTNode<SemanticData, TypeData>> -
    key.start? Expression<ExpressionSemantics, ExpressionTypeSemantics, CompilableASTNode<SemanticData, TypeData>> -

    Returns

    void

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:636


    validUnaryExpression

    ▸ validUnaryExpression(operand): void

    Asserts that the passed unary expression is valid by checking its operand.semanticData.operand operand and operand.semanticData.operator operator.

    Throws

    If the operand is not a valid operand for the operator.

    Since

    0.9.0

    Parameters

    Name Type Description
    operand IncrementOrDecrementPostfixExpression | UnaryExpression<UnaryExpressionSemantics, UnaryExpressionTypeSemantics> The unary expression to check. (Also includes IncrementOrDecrementPostfixExpression, since even if it's a postfix expression, it's still a unary expression)

    Returns

    void

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:346


    validVariableDefinition

    ▸ validVariableDefinition(scopeEntry, value): void

    Asserts that this variable definition is valid and the assigned value is compatible with the identifier.

    Throws

    If the assignment value type is not compatible with the definition type.

    Since

    0.7.0

    Parameters

    Name Type Description
    scopeEntry ScopeVariableDeclaration The scope entry/variable being assigned to.
    value Expression<ExpressionSemantics, ExpressionTypeSemantics, CompilableASTNode<SemanticData, TypeData>> The right expression/value of the assignment.

    Returns

    void

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:238


    getTypeForAnalysis

    ▸ Static getTypeForAnalysis(type): undefined | KipperCompilableType

    Gets the type that should be used for the type checking from the provided CheckedType.

    This function is intended to check for UndefinedCustomType, which is a special type that is created during error recovery to indicate a type is invalid/undefined. This type should be always ignored and as such this function will return undefined, so that they type checking is skipped. (This is fine, since the compiler should have already thrown an error at the creation of the UndefinedCustomType.)

    Parameters

    Name Type Description
    type CheckedType The CheckedType instance.

    Returns

    undefined | KipperCompilableType

    Defined in

    kipper/core/src/compiler/analysis/analyser/type-checker.ts:88

  • Developed at:

    • Releases
    • GitHub
    • Security
    • Issue Tracker
    • License
  • Copyright © 2021-2026 Luna Klatzer, 2024-2025 Lorenz Holzbauer & Fabian Baitura.
    Kipper is licensed under the GPL-3.0-or-later license.