Closed chengda300 closed 1 month ago
The functions are actually pushing the correct number of return values. However, as the CallInstruction took the compile-time argument length (where functions are assumed to return only 1 value at compile-time), functions that return more than 1 value are counted as only 1 argument instead of the number of return values as argument length.
The following kinds of error surface as a result:
a, b := f(0) where f(x) returns 2 values -> compile error, assignment mismatch: 2 variable(s) but 1 value(s). f(0) is assumed to have only 1 return value but it has 2 return values
fmt.Println(f(0)) where f(x) returns 2 values which are both non-functions -> runtime error, stack does not contain closure As fmt.Println was expecting only 1 argument instead of 2. Due to the misalignment, it went from (println) (f(0)) (call) to (1st return value of f(0)) (2nd return value of f(0)) (call). The 1st return value of f(0) is taken to be the function, when it is actually not a function, and a runtime error occurs.
Functions for now can only return a single variable