Commit 082934db authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

report error when using `this' or `base' access outside of instance

2008-04-17  Juerg Billeter  <j@bitron.ch>

	* vala/valasemanticanalyzer.vala: report error when using `this' or
	  `base' access outside of instance methods

svn path=/trunk/; revision=1252
parent 8ebcd01f
2008-04-17 Jürg Billeter <j@bitron.ch>
* vala/valasemanticanalyzer.vala: report error when using `this' or
`base' access outside of instance methods
2008-04-16 Marc-Andre Lureau <marcandre.lureau@gmail.com>
* vapi/glib-2.0.vapi (EnumClass, FlagsClass, FlagsValue): complete
......
......@@ -1482,6 +1482,14 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
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 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
}
}
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 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
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);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment