vala r1499 - in trunk: . vala
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r1499 - in trunk: . vala
- Date: Fri, 30 May 2008 20:44:41 +0000 (UTC)
Author: juergbi
Date: Fri May 30 20:44:41 2008
New Revision: 1499
URL: http://svn.gnome.org/viewvc/vala?rev=1499&view=rev
Log:
2008-05-30 JÃrg Billeter <j bitron ch>
* vala/valaobjecttype.vala:
* vala/valasemanticanalyzer.vala:
* vala/valasignal.vala:
Check return type and parameters of signal handlers
Modified:
trunk/ChangeLog
trunk/vala/valaobjecttype.vala
trunk/vala/valasemanticanalyzer.vala
trunk/vala/valasignal.vala
Modified: trunk/vala/valaobjecttype.vala
==============================================================================
--- trunk/vala/valaobjecttype.vala (original)
+++ trunk/vala/valaobjecttype.vala Fri May 30 20:44:41 2008
@@ -54,4 +54,21 @@
public override string? get_cname () {
return "%s*".printf (type_symbol.get_cname (!value_owned));
}
+
+ public override bool stricter (DataType target_type) {
+ var obj_target_type = target_type as ObjectType;
+ if (obj_target_type == null) {
+ return false;
+ }
+
+ if (value_owned != target_type.value_owned) {
+ return false;
+ }
+
+ if (nullable && !target_type.nullable) {
+ return false;
+ }
+
+ return type_symbol.is_subtype_of (obj_target_type.type_symbol);
+ }
}
Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala (original)
+++ trunk/vala/valasemanticanalyzer.vala Fri May 30 20:44:41 2008
@@ -3096,6 +3096,8 @@
l.symbol_reference = l.method;
l.accept_children (this);
+
+ l.value_type = new MethodType (l.method);
}
public override void visit_assignment (Assignment a) {
@@ -3133,7 +3135,7 @@
// target_type not available for dynamic signals
} else if (ma.symbol_reference is Signal) {
var sig = (Signal) ma.symbol_reference;
- a.right.target_type = new DelegateType (sig.get_delegate ());
+ a.right.target_type = new DelegateType (sig.get_delegate (ma.inner.value_type));
} else {
a.right.target_type = ma.value_type;
}
@@ -3205,7 +3207,9 @@
if (ma.symbol_reference is Signal) {
var sig = (Signal) ma.symbol_reference;
- if (a.right.symbol_reference == null) {
+ var m = a.right.symbol_reference as Method;
+
+ if (m == null) {
a.error = true;
Report.error (a.right.source_reference, "unsupported expression for signal handler");
return;
@@ -3222,7 +3226,11 @@
dynamic_sig.add_parameter (param);
}
}
- a.right.target_type = new DelegateType (sig.get_delegate ());
+ a.right.target_type = new DelegateType (sig.get_delegate (new ObjectType ((ObjectTypeSymbol) sig.parent_symbol)));
+ } else if (!a.right.value_type.compatible (a.right.target_type)) {
+ a.error = true;
+ Report.error (a.right.source_reference, "method `%s' is incompatible with signal `%s'".printf (a.right.value_type.to_string (), a.right.target_type.to_string ()));
+ return;
}
} else if (ma.symbol_reference is Property) {
var prop = (Property) ma.symbol_reference;
Modified: trunk/vala/valasignal.vala
==============================================================================
--- trunk/vala/valasignal.vala (original)
+++ trunk/vala/valasignal.vala Fri May 30 20:44:41 2008
@@ -49,7 +49,6 @@
public bool is_virtual { get; set; }
private Gee.List<FormalParameter> parameters = new ArrayList<FormalParameter> ();
- private Delegate generated_delegate;
private Method generated_method;
private string cname;
@@ -96,28 +95,19 @@
*
* @return delegate
*/
- public Delegate? get_delegate () {
- // parent_symbol is null for D-Bus signals
- if (generated_delegate == null && parent_symbol != null) {
- generated_delegate = new Delegate (null, return_type);
- generated_delegate.has_target = true;
-
- ReferenceType sender_type;
- if (parent_symbol is Class) {
- sender_type = new ObjectType ((Class) parent_symbol);
- } else {
- sender_type = new ObjectType ((Interface) parent_symbol);
- }
- var sender_param = new FormalParameter ("_sender", sender_type);
- generated_delegate.add_parameter (sender_param);
-
- foreach (FormalParameter param in parameters) {
- generated_delegate.add_parameter (param);
- }
+ public Delegate get_delegate (DataType sender_type) {
+ var generated_delegate = new Delegate (null, return_type);
+ generated_delegate.has_target = true;
- scope.add (null, generated_delegate);
+ var sender_param = new FormalParameter ("_sender", sender_type.copy ());
+ generated_delegate.add_parameter (sender_param);
+
+ foreach (FormalParameter param in parameters) {
+ generated_delegate.add_parameter (param);
}
-
+
+ scope.add (null, generated_delegate);
+
return generated_delegate;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]