[vala/staging] vala: Don't carry floating reference into unknown target type expression
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Don't carry floating reference into unknown target type expression
- Date: Fri, 26 Jun 2020 13:34:46 +0000 (UTC)
commit eb797855ec320dfcfe50cfa3bf056dc999ee3782
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Fri Jun 26 15:27:11 2020 +0200
vala: Don't carry floating reference into unknown target type expression
A floating reference result of a method, which may throw an error, needs
to be sinked when passed as argument for ellipsis parameter.
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1018
tests/Makefile.am | 1 +
tests/semantic/floating-reference-error.vala | 22 ++++++++++++++++++++++
tests/semantic/floating-reference.vala | 17 +++++++++++++++++
vala/valamethodcall.vala | 5 +++++
4 files changed, 45 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 02af2fd59..35b610d2a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -821,6 +821,7 @@ TESTS = \
semantic/field-valist.test \
semantic/field-void.test \
semantic/floating-reference.vala \
+ semantic/floating-reference-error.vala \
semantic/foreach-iterator-args.test \
semantic/foreach-iterator-element-owned.test \
semantic/foreach-iterator-void.test \
diff --git a/tests/semantic/floating-reference-error.vala b/tests/semantic/floating-reference-error.vala
new file mode 100644
index 000000000..37839d683
--- /dev/null
+++ b/tests/semantic/floating-reference-error.vala
@@ -0,0 +1,22 @@
+[CCode (returns_floating_reference = true)]
+Variant? get_floating_variant_with_error () throws Error {
+ return new Variant.string ("bar");
+}
+
+void variant_args (int first, ...) {
+ var va = va_list ();
+ assert (!va.arg<Variant> ().is_floating ());
+}
+
+void main () {
+ {
+ variant_args (23, get_floating_variant_with_error ());
+ }
+ {
+ try {
+ variant_args (42, get_floating_variant_with_error ());
+ } catch {
+ assert_not_reached ();
+ }
+ }
+}
diff --git a/tests/semantic/floating-reference.vala b/tests/semantic/floating-reference.vala
index f690d690d..3cba74865 100644
--- a/tests/semantic/floating-reference.vala
+++ b/tests/semantic/floating-reference.vala
@@ -3,6 +3,11 @@ Variant get_floating_variant () {
return new Variant.string ("foo");
}
+[CCode (returns_floating_reference = true)]
+Variant? get_floating_variant_with_error () throws Error {
+ return new Variant.string ("bar");
+}
+
void test_variant () {
{
string? @value = "bar";
@@ -45,6 +50,18 @@ void test_variant () {
Variant? variant = get_floating_variant ();
assert (!variant.is_floating ());
}
+ {
+ Variant? variant = get_floating_variant_with_error ();
+ assert (!variant.is_floating ());
+ }
+ {
+ try {
+ Variant? variant = get_floating_variant_with_error ();
+ assert (!variant.is_floating ());
+ } catch {
+ assert_not_reached ();
+ }
+ }
}
void test_variant_builder () {
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 3573113c4..baf704f45 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -664,6 +664,11 @@ public class Vala.MethodCall : Expression {
var local = new LocalVariable (value_type.copy (), get_temp_name (), null,
source_reference);
var decl = new DeclarationStatement (local, source_reference);
+ // don't carry floating reference any further if the target-type is unknown
+ if (target_type == null) {
+ local.variable_type.floating_reference = false;
+ }
+
insert_statement (context.analyzer.insert_block, decl);
var temp_access = SemanticAnalyzer.create_temp_access (local, target_type);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]