]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Fix symbol resolution for local constants
authorLuca Bruno <lucabru@src.gnome.org>
Tue, 2 Aug 2011 10:07:31 +0000 (12:07 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Tue, 2 Aug 2011 10:07:31 +0000 (12:07 +0200)
Fixes bug 649562.

codegen/valaccodeattribute.vala
tests/Makefile.am
tests/methods/bug649562.vala [new file with mode: 0644]
vala/valaconstant.vala
vala/valasemanticanalyzer.vala
vala/valasymbolresolver.vala

index b28e96843f50223a7d9b89fe84d05045fd67b47e..e97406465f7ad76ed3b773bc91bfa7fb3f4ee4d4 100644 (file)
@@ -493,6 +493,10 @@ public class Vala.CCodeAttribute : AttributeCache {
                var sym = node as Symbol;
                if (sym != null) {
                        if (sym is Constant && !(sym is EnumValue)) {
+                               if (sym.parent_symbol is Block) {
+                                       // local constant
+                                       return sym.name;
+                               }
                                return "%s%s".printf (CCodeBaseModule.get_ccode_lower_case_prefix (sym.parent_symbol).up (), sym.name);
                        } else if (sym is Field) {
                                if (((Field) sym).binding == MemberBinding.STATIC) {
index eac0891a172c2afd010c102ae6c5832800fdc755..09ca1a50e193c911eae2da9cb3e1a3ccfee58e1a 100644 (file)
@@ -42,6 +42,7 @@ TESTS = \
        methods/bug642899.vala \
        methods/bug646345.vala \
        methods/bug648320.vala \
+       methods/bug649562.vala \
        methods/bug653391.vala \
        methods/bug653908.vala \
        control-flow/break.vala \
diff --git a/tests/methods/bug649562.vala b/tests/methods/bug649562.vala
new file mode 100644 (file)
index 0000000..d7f53ee
--- /dev/null
@@ -0,0 +1,9 @@
+void main () {
+       {
+               const int a = 2;
+       }
+       SourceFunc f = () => {
+               const int b = 3;
+               return false;
+       };
+}
index 7361f9b06f13b8685e92b70f5959bc2db32acbf2..b805203a0a59078f759eca2b8170bd041d3b3a79 100644 (file)
@@ -118,7 +118,10 @@ public class Vala.Constant : Symbol, Lockable {
                if (source_reference != null) {
                        context.analyzer.current_source_file = source_reference.file;
                }
-               context.analyzer.current_symbol = this;
+               if (!(parent_symbol is Block)) {
+                       // non-local constant
+                       context.analyzer.current_symbol = this;
+               }
 
                type_reference.check (context);
 
index 97f910deafaa80484677f06187ff4c4b8b7f5d54..48cd70da9f7111228a19412e191ad9946518e227 100644 (file)
@@ -59,7 +59,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        public Method? current_method {
                get {
                        unowned Symbol sym = current_symbol;
-                       while (sym is Block || sym is Constant) {
+                       while (sym is Block) {
                                sym = sym.parent_symbol;
                        }
                        return sym as Method;
@@ -69,7 +69,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        public Method? current_async_method {
                get {
                        unowned Symbol sym = current_symbol;
-                       while (sym is Block || sym is Constant || sym is Method) {
+                       while (sym is Block || sym is Method) {
                                var m = sym as Method;
                                if (m != null && m.coroutine) {
                                        break;
@@ -84,7 +84,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        public PropertyAccessor? current_property_accessor {
                get {
                        unowned Symbol sym = current_symbol;
-                       while (sym is Block || sym is Constant) {
+                       while (sym is Block) {
                                sym = sym.parent_symbol;
                        }
                        return sym as PropertyAccessor;
@@ -94,7 +94,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        public Symbol? current_method_or_property_accessor {
                get {
                        unowned Symbol sym = current_symbol;
-                       while (sym is Block || sym is Constant) {
+                       while (sym is Block) {
                                sym = sym.parent_symbol;
                        }
                        if (sym is Method) {
@@ -873,14 +873,14 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        }
 
        public Method? find_parent_method (Symbol sym) {
-               while (sym is Block || sym is Constant) {
+               while (sym is Block) {
                        sym = sym.parent_symbol;
                }
                return sym as Method;
        }
 
        public Symbol? find_parent_method_or_property_accessor (Symbol sym) {
-               while (sym is Block || sym is Constant) {
+               while (sym is Block) {
                        sym = sym.parent_symbol;
                }
                if (sym is Method) {
index 3f874fa240d7bb252fdf9a9e3586f111fa9bdf43..f11d74ee6f475685fe0f873b273c1ff9ffb1c85d 100644 (file)
@@ -159,7 +159,10 @@ public class Vala.SymbolResolver : CodeVisitor {
 
        public override void visit_constant (Constant c) {
                var old_scope = current_scope;
-               current_scope = c.scope;
+               if (!(c.parent_symbol is Block)) {
+                       // non-local constant
+                       current_scope = c.scope;
+               }
 
                c.accept_children (this);