summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2021-09-18 23:30:31 +0200
committerRico Tzschichholz <ricotz@ubuntu.com>2021-09-22 15:26:46 +0200
commite2bb9209d132f408655805ec8b7d3a9db2a0fc44 (patch)
tree64c7759c2bfe70131046cf132c7b3bbfcbcf991b
parent0d7d1728eeaeefb201de12dc6724dc52bff8ce4e (diff)
downloadvala-e2bb9209d132f408655805ec8b7d3a9db2a0fc44.tar.gz
codegen: Add type declaration for implicit temporary local variable
-rw-r--r--codegen/valaccodebasemodule.vala2
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/delegates/implicit-local-variable.vala6
3 files changed, 9 insertions, 0 deletions
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 14aa846f9..c65fda753 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3912,6 +3912,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 3671f3312..fbc25c3bc 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -397,6 +397,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/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);
+}