LensPlaysGames/LensorCompilerCollection

"Silent" error when using variable before it's definition

LensPlaysGames opened this issue · 5 comments

I'm not sure what's going wrong here, but when using a variable as if it's been defined, even though it hasn't, there are no user-facing errors other than a return code of 2...

foo : integer(state : integer) {
  idx := 0
  while idx < colcount {
    ;;putchar(
    ;;  if state & (1 << idx) {
    ;;    42
    ;;  } else {
    ;;    32
    ;;  }
    ;;)
    if state & (1 << idx) {
      putchar(42)
    } else {
      putchar(32)
    }
    idx := idx + 1
  }
  putchar(10)
}

idx : integer = 0
foo(1)

NOTE: No output file is ever written. It looks like we are exiting from https://github.com/LensPlaysGames/FUNCompiler/blob/17c4d1bc8f45f093b10638423044ebd0748b5256/src/main.c#L304 silently, which is very not ideal.

This is most likely caused by #27

This is most likely caused by #27

@Sirraide #27 is fixed (for example, tst/tests/redef.un now errors as expected) and closed, but this issue still remains. Still exiting silently with exit code 2, from the same place after typechecking (somehow) fails.

I think variable lookup may be a bit broken atm...

Example at examples/vec2.int is also suffering from the same problem.

vec2 :> type {
  x : integer
  y : integer
}

vec2_add : vec2(a : vec2, b : vec2) {
  out : vec2
  out.x := a.x + b.x
  out.y := a.y + b.y
  out
}

a : vec2
a.x := 34
b : vec2
b.a := 420
b.x := 35

vec2_add(a, b).y

Fixed!