[vala/staging] 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/staging] vala: Keep formal_target_type when transforming method-call/object-creation
- Date: Tue, 19 Nov 2019 08:51:30 +0000 (UTC)
commit f4bad5fc9b05672d304472f149b416e2d0f6da82
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 01161db0a..9d2e5cc6d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -508,6 +508,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/member-dup-destroy.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 9aaa0dd04..1c6e2b404 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -646,6 +646,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
@@ -662,6 +663,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 caf9414a6..575d50b37 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -499,6 +499,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
@@ -515,6 +516,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]