Skip to content

Latest commit

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..

README.md

Klar Analysis / Type Checker

Grammar

In compatibility.go, you'll see syntax in comments that describe typing properties.

  • A => B means type A is assignable to B.
  • Uppercase letters are type variables. A => A refers to the same type on both sides.
  • Lowercase letters are variables (not types). Types can be assigned to them using the syntax a: T, meaning variable a has type T.
  • Klar type syntax is also used, so [A] is a list, and A | B is a union type.
  • if, and and or are also used. A => B | C if A => B or A => C means type A is compatible with the union of B and C, if A is assignable to either B or C.
  • A =!> B means type A is not assignable to B.
  • A = B means type A is equal to B (similar meaning for !=).
  • A <=> B means type A is assignable to B and vice versa.

Overload Resolution

Overload Declaration Rules

Variadics

Either all or no overloads must have variadic positional parameters.

Not allowedNot allowed
func(...Int)
func(Int, Int)
func(String, ...Int)
func(...String | Int)
func(String, Int)

Compatibility

Allowed (interface/tag)Not allowed (union)
type #Vehicle
type Car {}

func(Vehicle)
func(Car)
func(A | B)
func(A)

Optionals

Not allowedNot allowed
func(Int?)
func(Int)
func(String, Int, Bool)
func(String, Int?, Bool)