diff options
-rw-r--r-- | codegen/valaccodeattribute.vala | 4 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/methods/bug649562.vala | 9 | ||||
-rw-r--r-- | vala/valaconstant.vala | 5 | ||||
-rw-r--r-- | vala/valasemanticanalyzer.vala | 12 | ||||
-rw-r--r-- | vala/valasymbolresolver.vala | 5 |
6 files changed, 28 insertions, 8 deletions
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala index b28e96843..e97406465 100644 --- a/codegen/valaccodeattribute.vala +++ b/codegen/valaccodeattribute.vala @@ -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) { diff --git a/tests/Makefile.am b/tests/Makefile.am index eac0891a1..09ca1a50e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..d7f53eeef --- /dev/null +++ b/tests/methods/bug649562.vala @@ -0,0 +1,9 @@ +void main () { + { + const int a = 2; + } + SourceFunc f = () => { + const int b = 3; + return false; + }; +} diff --git a/vala/valaconstant.vala b/vala/valaconstant.vala index 7361f9b06..b805203a0 100644 --- a/vala/valaconstant.vala +++ b/vala/valaconstant.vala @@ -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); diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index 97f910dea..48cd70da9 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -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) { diff --git a/vala/valasymbolresolver.vala b/vala/valasymbolresolver.vala index 3f874fa24..f11d74ee6 100644 --- a/vala/valasymbolresolver.vala +++ b/vala/valasymbolresolver.vala @@ -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); |