sim-c icon indicating copy to clipboard operation
sim-c copied to clipboard

[BUG] Return type and dtype of parameters in a function is incorrect

Open frankhart2018 opened this issue 3 years ago • 0 comments

Describe the bug In the current implementation if a function is called with parameters of different types then the compiled C version of the function has the type from the final call, but the return type is set from the very first call. There can be two resolutions to this problem:-

  1. Throw an error when types change
  2. Name mangling (Follow this source if you don't know what name mangling means).

Steps to Reproduce

For this simC code:-

fun sum(a, b) {
	return a + b
}

MAIN
	var res = sum(1, 2)
	var res1 = sum(3.14, 4.2)
END_MAIN

The following C code is generated:-

int sum(float a, float b) {

	return a + b;
}

int main() {
	int res = sum(1, 2);
	int res1 = sum(3.14, 4.2);

	return 0;
}

Note: I have started a discussion for this, if anyone wants to work in this then please express your views regarding both the choices in this discussion:- 484.

frankhart2018 avatar Jan 26 '21 14:01 frankhart2018