summaryrefslogtreecommitdiff
path: root/vala
diff options
context:
space:
mode:
authorJuerg Billeter <j@bitron.ch>2007-08-30 19:54:32 +0000
committerJürg Billeter <juergbi@src.gnome.org>2007-08-30 19:54:32 +0000
commit233d33173f8d6467e9988cb2fd65898b29b64ec3 (patch)
treef7a65a5b4462faa98b56e8f2d28e55eedc339a93 /vala
parent6accf66c7fabe2db728790a4d80ad087b70fbc12 (diff)
downloadvala-233d33173f8d6467e9988cb2fd65898b29b64ec3.tar.gz
support prototype access to allow accessing instance members without an
2007-08-30 Juerg Billeter <j@bitron.ch> * vala/valamemberaccess.vala, vala/valasemanticanalyzer.vala: support prototype access to allow accessing instance members without an actual instance, fixes bug 471778 svn path=/trunk/; revision=547
Diffstat (limited to 'vala')
-rw-r--r--vala/valamemberaccess.vala6
-rw-r--r--vala/valasemanticanalyzer.vala27
2 files changed, 28 insertions, 5 deletions
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 5f32ed50a..ece44b9fd 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -47,6 +47,12 @@ public class Vala.MemberAccess : Expression {
*/
public string! member_name { get; set; }
+ /**
+ * Represents access to an instance member without an actual instance,
+ * e.g. `MyClass.an_instance_method`.
+ */
+ public bool prototype_access { get; set; }
+
private Expression _inner;
private Gee.List<TypeReference> type_argument_list = new ArrayList<TypeReference> ();
diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala
index 479e23e9b..20d395219 100644
--- a/vala/valasemanticanalyzer.vala
+++ b/vala/valasemanticanalyzer.vala
@@ -1249,6 +1249,15 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
return;
}
+ if (expr.inner is MemberAccess) {
+ var ma = (MemberAccess) expr.inner;
+ if (ma.prototype_access) {
+ expr.error = true;
+ Report.error (expr.source_reference, "Access to instance member `%s' denied".printf (expr.inner.symbol_reference.get_full_name ()));
+ return;
+ }
+ }
+
if (expr.inner is MemberAccess || expr.inner is BaseAccess) {
base_symbol = expr.inner.symbol_reference;
if (base_symbol is Namespace || base_symbol is DataType) {
@@ -1321,14 +1330,13 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
}
}
if (instance && !may_access_instance_members) {
- expr.error = true;
- Report.error (expr.source_reference, "Access to instance member `%s' denied".printf (member.get_full_name ()));
- return;
+ expr.prototype_access = true;
+ // no static type for prototype access
+ } else {
+ expr.static_type = get_static_type_for_symbol (expr.symbol_reference);
}
current_source_file.add_symbol_dependency (expr.symbol_reference, SourceFileDependencyType.SOURCE);
-
- expr.static_type = get_static_type_for_symbol (expr.symbol_reference);
}
private bool is_type_compatible (TypeReference! expression_type, TypeReference! expected_type) {
@@ -1411,6 +1419,15 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
return;
}
+ if (expr.call is MemberAccess) {
+ var ma = (MemberAccess) expr.call;
+ if (ma.prototype_access) {
+ expr.error = true;
+ Report.error (expr.source_reference, "Access to instance member `%s' denied".printf (expr.call.symbol_reference.get_full_name ()));
+ return;
+ }
+ }
+
var msym = expr.call.symbol_reference;
if (msym == null) {