[vala] codegen: Support "foo is G"
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Support "foo is G"
- Date: Sat, 11 Jan 2014 16:06:06 +0000 (UTC)
commit e15a795130250de68c4ea9bf3205c58865732869
Author: Luca Bruno <lucabru src gnome org>
Date: Sat Jan 11 17:04:02 2014 +0100
codegen: Support "foo is G"
codegen/valaccodebasemodule.vala | 6 +++---
tests/methods/generics.vala | 11 +++++++++++
2 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 4f049c1..488d434 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5349,13 +5349,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var type_domain = new CCodeIdentifier (get_ccode_upper_case_name (et.error_domain));
return new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, instance_domain,
type_domain);
} else {
- string type_id = get_ccode_type_id (type.data_type);
- if (type_id == "") {
+ var type_id = get_type_id_expression (type);
+ if (type_id == null) {
return new CCodeInvalidExpression ();
}
var ccheck = new CCodeFunctionCall (new CCodeIdentifier
("G_TYPE_CHECK_INSTANCE_TYPE"));
ccheck.add_argument ((CCodeExpression) ccodenode);
- ccheck.add_argument (new CCodeIdentifier (type_id));
+ ccheck.add_argument (type_id);
return ccheck;
}
}
diff --git a/tests/methods/generics.vala b/tests/methods/generics.vala
index b465523..27e9cc1 100644
--- a/tests/methods/generics.vala
+++ b/tests/methods/generics.vala
@@ -4,6 +4,9 @@ interface Foo : Object {
}
}
+class Bar {
+}
+
class Baz : Object, Foo {
}
@@ -11,6 +14,11 @@ void foo<T> (owned T bar) {
bar = null;
}
+bool is_check<G> () {
+ var o = new Bar ();
+ return o is G;
+}
+
void main () {
var bar = new Object ();
foo<Object> (bar);
@@ -19,4 +27,7 @@ void main () {
var baz = new Baz ();
baz.foo<Object> (bar);
assert (baz.ref_count == 1);
+
+ assert (is_check<Bar> ());
+ assert (!is_check<Baz> ());
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]