diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-09-18 23:30:31 +0200 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-09-18 23:45:33 +0200 |
commit | ff0eda52ceb81d9eec68b732d693c85279116349 (patch) | |
tree | 3346c74adc05fcedf1fdc46f53a903a82b60d027 | |
parent | 0f3cc46f70252127074c040d9e7e1d2233a7c22d (diff) | |
download | vala-ff0eda52ceb81d9eec68b732d693c85279116349.tar.gz |
codegen: Add type declaration for implicit temporary local variable
-rw-r--r-- | codegen/valaccodebasemodule.vala | 2 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/annotations/description.c-expected | 2 | ||||
-rw-r--r-- | tests/asynchronous/catch-error-scope.c-expected | 2 | ||||
-rw-r--r-- | tests/asynchronous/catch-in-finally.c-expected | 2 | ||||
-rw-r--r-- | tests/delegates/implicit-local-variable.c-expected | 60 | ||||
-rw-r--r-- | tests/delegates/implicit-local-variable.vala | 6 | ||||
-rw-r--r-- | tests/enums/no_gtype_to_string.c-expected | 2 | ||||
-rw-r--r-- | tests/errors/bug639589.c-expected | 2 | ||||
-rw-r--r-- | tests/errors/catch-in-finally.c-expected | 2 | ||||
-rw-r--r-- | tests/errors/errors.c-expected | 2 | ||||
-rw-r--r-- | tests/generics/inference-static-function.c-expected | 2 | ||||
-rw-r--r-- | tests/methods/argument-named.c-expected | 2 | ||||
-rw-r--r-- | tests/namespace/unique.c-expected | 2 |
14 files changed, 89 insertions, 0 deletions
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index f7321b72a..06b745463 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -3993,6 +3993,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } public void emit_temp_var (LocalVariable local, bool on_error = false) { + generate_type_declaration (local.variable_type, cfile); + var init = (!local.name.has_prefix ("*") && local.init); if (is_in_coroutine ()) { closure_struct.add_field (get_ccode_name (local.variable_type), local.name, 0, get_ccode_declarator_suffix (local.variable_type)); diff --git a/tests/Makefile.am b/tests/Makefile.am index d84703e65..ed1ef5980 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -403,6 +403,7 @@ TESTS = \ delegates/fields.vala \ delegates/fields-no-target.vala \ delegates/gclosure-conversion.vala \ + delegates/implicit-local-variable.vala \ delegates/incompatible.test \ delegates/incompatible-assignment.test \ delegates/incompatible-initializer.test \ diff --git a/tests/annotations/description.c-expected b/tests/annotations/description.c-expected index 4dbb7e569..51dbbc592 100644 --- a/tests/annotations/description.c-expected +++ b/tests/annotations/description.c-expected @@ -3,6 +3,8 @@ #include <glib-object.h> #include <glib.h> +#include <stdlib.h> +#include <string.h> #if !defined(VALA_EXTERN) #if defined(_MSC_VER) diff --git a/tests/asynchronous/catch-error-scope.c-expected b/tests/asynchronous/catch-error-scope.c-expected index 77d20d30b..289b79029 100644 --- a/tests/asynchronous/catch-error-scope.c-expected +++ b/tests/asynchronous/catch-error-scope.c-expected @@ -3,6 +3,8 @@ #include <glib.h> #include <gio/gio.h> +#include <stdlib.h> +#include <string.h> #include <glib-object.h> #if !defined(VALA_EXTERN) diff --git a/tests/asynchronous/catch-in-finally.c-expected b/tests/asynchronous/catch-in-finally.c-expected index 3364392a0..9779a393a 100644 --- a/tests/asynchronous/catch-in-finally.c-expected +++ b/tests/asynchronous/catch-in-finally.c-expected @@ -4,6 +4,8 @@ #include <glib.h> #include <gio/gio.h> #include <glib-object.h> +#include <stdlib.h> +#include <string.h> #if !defined(VALA_EXTERN) #if defined(_MSC_VER) diff --git a/tests/delegates/implicit-local-variable.c-expected b/tests/delegates/implicit-local-variable.c-expected new file mode 100644 index 000000000..f38ba1dca --- /dev/null +++ b/tests/delegates/implicit-local-variable.c-expected @@ -0,0 +1,60 @@ +/* delegates_implicit_local_variable.c generated by valac, the Vala compiler + * generated from delegates_implicit_local_variable.vala, do not modify */ + +#include <glib.h> + +typedef gboolean (*GSourceDispatchFunc) (GSource* source, GSourceFunc _callback, gpointer _callback_target); +#define _g_source_unref0(var) ((var == NULL) ? NULL : (var = (g_source_unref (var), NULL))) + +static void _vala_main (void); +static gboolean __lambda4_ (void); +static gboolean ___lambda4__gsource_dispatch_func (GSource* source, + GSourceFunc _callback, + gpointer _callback_target); + +static gboolean +__lambda4_ (void) +{ + gboolean result = FALSE; + result = FALSE; + return result; +} + +static gboolean +___lambda4__gsource_dispatch_func (GSource* source, + GSourceFunc _callback, + gpointer _callback_target) +{ + gboolean result; + result = __lambda4_ (); + return result; +} + +static void +_vala_main (void) +{ + GSourceFuncs foo = {0}; + GSourceFuncs _tmp0_ = {0}; + GSource* bar = NULL; + GSourceFuncs _tmp1_; + GSourceDispatchFunc _tmp2_; + _tmp0_.prepare = NULL; + _tmp0_.check = NULL; + _tmp0_.dispatch = ___lambda4__gsource_dispatch_func; + _tmp0_.finalize = NULL; + foo = _tmp0_; + bar = NULL; + _tmp1_ = foo; + _tmp2_ = _tmp1_.dispatch; + _tmp2_ (bar, NULL, NULL); + _g_source_unref0 (bar); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/delegates/implicit-local-variable.vala b/tests/delegates/implicit-local-variable.vala new file mode 100644 index 000000000..ffe1d3175 --- /dev/null +++ b/tests/delegates/implicit-local-variable.vala @@ -0,0 +1,6 @@ +void main () { + SourceFuncs foo = { null, null, () => { return false; }, null }; + Source bar = null; + + foo.dispatch (bar, null); +} diff --git a/tests/enums/no_gtype_to_string.c-expected b/tests/enums/no_gtype_to_string.c-expected index 872f19b85..89201fa8b 100644 --- a/tests/enums/no_gtype_to_string.c-expected +++ b/tests/enums/no_gtype_to_string.c-expected @@ -3,6 +3,8 @@ #include <glib.h> #include <glib-object.h> +#include <stdlib.h> +#include <string.h> typedef enum { FOO_BAR, diff --git a/tests/errors/bug639589.c-expected b/tests/errors/bug639589.c-expected index 59ebaf508..f3e3c8212 100644 --- a/tests/errors/bug639589.c-expected +++ b/tests/errors/bug639589.c-expected @@ -3,6 +3,8 @@ #include <glib.h> #include <glib-object.h> +#include <stdlib.h> +#include <string.h> #if !defined(VALA_EXTERN) #if defined(_MSC_VER) diff --git a/tests/errors/catch-in-finally.c-expected b/tests/errors/catch-in-finally.c-expected index 43991a3dc..cecb359e8 100644 --- a/tests/errors/catch-in-finally.c-expected +++ b/tests/errors/catch-in-finally.c-expected @@ -2,6 +2,8 @@ * generated from errors_catch_in_finally.vala, do not modify */ #include <glib.h> +#include <stdlib.h> +#include <string.h> #if !defined(VALA_EXTERN) #if defined(_MSC_VER) diff --git a/tests/errors/errors.c-expected b/tests/errors/errors.c-expected index 4578d64f7..f688fd06f 100644 --- a/tests/errors/errors.c-expected +++ b/tests/errors/errors.c-expected @@ -4,6 +4,8 @@ #include <glib.h> #include <glib-object.h> #include <stdio.h> +#include <stdlib.h> +#include <string.h> #if !defined(VALA_EXTERN) #if defined(_MSC_VER) diff --git a/tests/generics/inference-static-function.c-expected b/tests/generics/inference-static-function.c-expected index e01e2be62..df2182982 100644 --- a/tests/generics/inference-static-function.c-expected +++ b/tests/generics/inference-static-function.c-expected @@ -4,6 +4,8 @@ #include <glib-object.h> #include <glib.h> #include <gobject/gvaluecollector.h> +#include <stdlib.h> +#include <string.h> #if !defined(VALA_EXTERN) #if defined(_MSC_VER) diff --git a/tests/methods/argument-named.c-expected b/tests/methods/argument-named.c-expected index b86950951..c44c032fa 100644 --- a/tests/methods/argument-named.c-expected +++ b/tests/methods/argument-named.c-expected @@ -4,6 +4,8 @@ #include <glib-object.h> #include <glib.h> #include <stdarg.h> +#include <stdlib.h> +#include <string.h> #include <gobject/gvaluecollector.h> #if !defined(VALA_EXTERN) diff --git a/tests/namespace/unique.c-expected b/tests/namespace/unique.c-expected index 10dd574b4..41ed4a820 100644 --- a/tests/namespace/unique.c-expected +++ b/tests/namespace/unique.c-expected @@ -4,6 +4,8 @@ #include <glib-object.h> #include <gobject/gvaluecollector.h> #include <glib.h> +#include <stdlib.h> +#include <string.h> #if !defined(VALA_EXTERN) #if defined(_MSC_VER) |