sophiajt / june

MIT License
813 stars 31 forks source link

Curried functions don't compile #68

Open tealeg opened 1 month ago

tealeg commented 1 month ago

Commit: f2107d4

Consider the following program:

fun areaOfCircle(pie: f64) -> fun(f64) -> f64 {
  fun f(r: f64) -> f64 {
    return pie * (r * r)
  }
  return f
}

fun main() {
  let pie = 3.14
  let aRadius = 8.4
  println(areaOfCircle(pie)(aRadius))     
}  

Currently this program gets through codegen, but clang will complain:

june build 
/home/tealeg/src/june-scratch/tll/build/debug/main.c:394:33: error: use of undeclared identifier 'variable_1'; did you mean 'variable_3'?
  394 | double return_expr = (/* pie */ variable_1)*((/* r */ variable_3)*(/* r */ variable_3));
      |                                 ^~~~~~~~~~
      |                                 variable_3
/home/tealeg/src/june-scratch/tll/build/debug/main.c:393:54: note: 'variable_3' declared here
  393 | double /* f */ function_3(long allocation_id, double variable_3){
      |                                                      ^
1 error generated.
thread 'main' panicked at src/main.rs:120:17:
Clang did not compile successfully
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Compilation exited abnormally with code 101 at Thu May  9 04:12:10