[vala/0.46] vala: Keep formal_target_type when transforming method-call/object-creation
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.46] vala: Keep formal_target_type when transforming method-call/object-creation
- Date: Wed, 5 Feb 2020 10:02:00 +0000 (UTC)
commit a2728f3eabe363f7c768a43f01e0972dfe5ea689
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Tue Nov 19 09:11:39 2019 +0100
vala: Keep formal_target_type when transforming method-call/object-creation
Fixes https://gitlab.gnome.org/GNOME/vala/issues/835
tests/Makefile.am | 1 +
tests/generics/inference-argument-may-fail.vala | 20 ++++++++++++++++++++
vala/valamethodcall.vala | 2 ++
vala/valaobjectcreationexpression.vala | 3 +++
4 files changed, 26 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 86e2be991..b2acf4824 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -498,6 +498,7 @@ TESTS = \
asynchronous/yield.vala \
generics/arrays-not-supported.test \
generics/constructor-chain-up.vala \
+ generics/inference-argument-may-fail.vala \
generics/inference-static-function.vala \
generics/parameter-sizeof-initializer.vala \
generics/type-parameter-properties.vala \
diff --git a/tests/generics/inference-argument-may-fail.vala b/tests/generics/inference-argument-may-fail.vala
new file mode 100644
index 000000000..b99b97153
--- /dev/null
+++ b/tests/generics/inference-argument-may-fail.vala
@@ -0,0 +1,20 @@
+class Foo<G> {
+ public Foo () throws Error {
+ }
+}
+
+Foo<string>? foo () throws Error {
+ return null;
+}
+
+G bar<G> (Foo<G>? foo) {
+ return null;
+}
+
+void main () {
+ try {
+ bar (foo ());
+ bar (new Foo<string> ());
+ } catch {
+ }
+}
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index c1b034fa3..7d4117e69 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -651,6 +651,7 @@ public class Vala.MethodCall : Expression {
value_type.check (context);
+ // FIXME code duplication in ObjectCreationExpression.check
if (tree_can_fail) {
if (parent_node is LocalVariable || parent_node is ExpressionStatement) {
// simple statements, no side effects after method call
@@ -667,6 +668,7 @@ public class Vala.MethodCall : Expression {
insert_statement (context.analyzer.insert_block, decl);
var temp_access = SemanticAnalyzer.create_temp_access (local, target_type);
+ temp_access.formal_target_type = formal_target_type;
// don't set initializer earlier as this changes parent_node and
parent_statement
local.initializer = this;
diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala
index 10e195742..87adc2ed2 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -495,6 +495,7 @@ public class Vala.ObjectCreationExpression : Expression {
context.analyzer.visit_member_initializer (init, type_reference);
}
+ // FIXME code duplication in MethodCall.check
if (tree_can_fail) {
if (parent_node is LocalVariable || parent_node is ExpressionStatement) {
// simple statements, no side effects after method call
@@ -511,6 +512,8 @@ public class Vala.ObjectCreationExpression : Expression {
insert_statement (context.analyzer.insert_block, decl);
var temp_access = SemanticAnalyzer.create_temp_access (local, target_type);
+ temp_access.formal_target_type = formal_target_type;
+
// don't set initializer earlier as this changes parent_node and
parent_statement
local.initializer = this;
decl.check (context);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]