diff --git a/vlib/compiler/cheaders.v b/vlib/compiler/cheaders.v index 8172c77dd6..e6920c7a0c 100644 --- a/vlib/compiler/cheaders.v +++ b/vlib/compiler/cheaders.v @@ -57,8 +57,10 @@ CommonCHeaders = ' #define TCCSKIP(x) x #ifdef __TINYC__ +#undef EMPTY_STRUCT_DECLARATION #undef EMPTY_STRUCT_INITIALIZATION -#define EMPTY_STRUCT_INITIALIZATION +#define EMPTY_STRUCT_DECLARATION char _dummy +#define EMPTY_STRUCT_INITIALIZATION 0 #undef EMPTY_ARRAY_OF_ELEMS #define EMPTY_ARRAY_OF_ELEMS(x,n) (x[n]) #undef TCCSKIP diff --git a/vlib/compiler/tests/fn_expecting_ref_but_returning_struct_test.v b/vlib/compiler/tests/fn_expecting_ref_but_returning_struct_test.v new file mode 100644 index 0000000000..9e8d4727d3 --- /dev/null +++ b/vlib/compiler/tests/fn_expecting_ref_but_returning_struct_test.v @@ -0,0 +1,23 @@ +struct Foo { +} +fn (f Foo) str() string { return 'Foo{}' } + +fn process_foo(foo &Foo) { + println('>process_foo, called for ${foo} === ${*foo}') +} + +fn get_foo() Foo { + println('>get_foo') + return Foo{} +} + +/* +// TODO: Fix this. It 'works' only with tcc, but is not stable. +fn test_ref_fn_arg() { + process_foo(get_foo()) + println(3434) + assert true +} +*/ + +fn test_dummy(){} diff --git a/vlib/compiler/tests/fn_expecting_ref_but_returning_struct_time_module_test.v b/vlib/compiler/tests/fn_expecting_ref_but_returning_struct_time_module_test.v new file mode 100644 index 0000000000..e86957456a --- /dev/null +++ b/vlib/compiler/tests/fn_expecting_ref_but_returning_struct_time_module_test.v @@ -0,0 +1,21 @@ +/* +// TODO: Fix this. +import time + +// using a manual temporary intermediate variable should always work: +fn test_call_fn_that_requires_reference_with_function_that_returns_a_struct_manual(){ + t1 := time.random() + t2 := t1.calc_unix() + println('tmp: $t2') + assert true +} + +// v should produce temporary intermediate variables in chained calls: +fn test_call_fn_that_requires_reference_with_function_that_returns_a_struct_chained(){ + res := (time.random().calc_unix()) + println('res: $res') + assert true +} +*/ + +fn test_dummy(){} diff --git a/vlib/compiler/tests/fn_test.v b/vlib/compiler/tests/fn_test.v index d225303fcc..d19b57d528 100644 --- a/vlib/compiler/tests/fn_test.v +++ b/vlib/compiler/tests/fn_test.v @@ -21,8 +21,6 @@ multi line comment (3) multi line comment (2) */ -import time - type myfn fn (int) string type myfn2 fn (a int, b int) int @@ -120,35 +118,3 @@ fn high_fn_multi_return(a int, b fn (c []int, d []string) ([]int, []string)) { fn test_fns() { // no asserts for now, just test function declarations above } - -struct Foo { -} - - -fn process_foo(foo &Foo) { -} - -fn get_foo() Foo { - return Foo{} -} - - -// This used to be broken. -fn test_ref_fn_arg() { - // TODO tcc bug - /* - $if !tinyc { - process_foo(get_foo()) - println(3434) - assert true - } - */ - - /* - res := (time.random().calc_unix()) - println(res) - assert true - */ - -} -