vala r1252 - in trunk: . vala
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r1252 - in trunk: . vala
- Date: Thu, 17 Apr 2008 21:01:36 +0100 (BST)
Author: juergbi
Date: Thu Apr 17 21:01:36 2008
New Revision: 1252
URL: http://svn.gnome.org/viewvc/vala?rev=1252&view=rev
Log:
2008-04-17 Juerg Billeter <j bitron ch>
* vala/valasemanticanalyzer.vala: report error when using `this' or
`base' access outside of instance methods
Modified:
trunk/ChangeLog
trunk/vala/valasemanticanalyzer.vala
Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala (original)
+++ trunk/vala/valasemanticanalyzer.vala Thu Apr 17 21:01:36 2008
@@ -1482,6 +1482,14 @@
expr.symbol_reference = null;
if (expr.inner == null) {
+ if (expr.member_name == "this") {
+ if (!is_in_instance_method ()) {
+ expr.error = true;
+ Report.error (expr.source_reference, "This access invalid outside of instance methods");
+ return;
+ }
+ }
+
base_symbol = current_symbol;
var sym = current_symbol;
@@ -2138,7 +2146,33 @@
}
}
+ private bool is_in_instance_method () {
+ var sym = current_symbol;
+ while (sym != null) {
+ if (sym is CreationMethod) {
+ return true;
+ } else if (sym is Method) {
+ var m = (Method) sym;
+ return m.instance;
+ } else if (sym is Constructor) {
+ var c = (Constructor) sym;
+ return c.instance;
+ } else if (sym is Property) {
+ return true;
+ }
+ sym = sym.parent_symbol;
+ }
+
+ return false;
+ }
+
public override void visit_base_access (BaseAccess expr) {
+ if (!is_in_instance_method ()) {
+ expr.error = true;
+ Report.error (expr.source_reference, "Base access invalid outside of instance methods");
+ return;
+ }
+
if (current_class == null) {
if (current_struct == null) {
expr.error = true;
@@ -2152,6 +2186,10 @@
Iterator<DataType> base_type_it = current_struct.get_base_types ().iterator ();
base_type_it.next ();
expr.static_type = base_type_it.get ();
+ } else if (current_class.base_class == null) {
+ expr.error = true;
+ Report.error (expr.source_reference, "Base access invalid without base class");
+ return;
} else {
expr.static_type = new ClassType (current_class.base_class);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]