Type Checker

Below is an example showcasing the capabilities of the type checker.

Galaxy example with type errors

const int b; // Const without initializer.

void Bar() { }

void Foo() {
  if (3 == true) // Cannot compare int and bool.
  {

  }
  
  NonExistingFunc(); // Not in scope
  int someInt = nonExistingVariable; // Not in scope
  
  Bar(3); // Bad argument count.
  nonExistingTyp bla; // Non existing type.
  Foo();
}

void Foo() { } // DuplicateName

int Bliep() {
  return true; //Bad return type.
}

Output from the example

errors

Encountered error(s) while compiling file testfiles/typErrors.galaxy
 
Constant "b"(located at "typErrors.galaxy" (line 3, column 11)) has no initializer.
 
Function call (located at "typErrors.galaxy" (line 8, column 9)) could not find a function "==" taking parameters: (OneOf{fixed,  int},  "bool"(located at "typErrors.galaxy" (line 8, column 9)))
 
Identifier "NonExistingFunc"(located at "typErrors.galaxy" (line 13, column 3)) is not defined.
 
Identifier "nonExistingVariable"(located at "typErrors.galaxy" (line 14, column 17)) is not defined.
 
Function call (located at "typErrors.galaxy" (line 16, column 3)) could not find a function "Bar" taking parameters: (OneOf{fixed,  int})
 
Identifier "nonExistingTyp"(located at "typErrors.galaxy" (line 17, column 3)) is not defined.
 
Identifier "Foo"(located at "typErrors.galaxy" (line 21, column 6)) defined with type void Func () is already defined with the same type "void"(located at "typErrors.galaxy" (line 7, column 1)) Func ()
 
Function "Bliep"(located at "typErrors.galaxy" (line 23, column 5)) with return type "int"(located at "typErrors.galaxy" (line 23, column 1)) tried to return with typ "bool"(located at "typErrors.galaxy" (line 24, column 3))

Comments

Posts Quoted:
Reply
Clear All Quotes