[vala] Fix symbol resolution for local constants
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Fix symbol resolution for local constants
- Date: Tue, 2 Aug 2011 10:09:52 +0000 (UTC)
commit 021ea9a87dd5f9159353bff72607c6eab2c18183
Author: Luca Bruno <lucabru src gnome org>
Date: Tue Aug 2 12:07:31 2011 +0200
Fix symbol resolution for local constants
Fixes bug 649562.
codegen/valaccodeattribute.vala | 4 ++++
tests/Makefile.am | 1 +
tests/methods/bug649562.vala | 9 +++++++++
vala/valaconstant.vala | 5 ++++-
vala/valasemanticanalyzer.vala | 12 ++++++------
vala/valasymbolresolver.vala | 5 ++++-
6 files changed, 28 insertions(+), 8 deletions(-)
---
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index b28e968..e974064 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 eac0891..09ca1a5 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 0000000..d7f53ee
--- /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 7361f9b..b805203 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 97f910d..48cd70d 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 3f874fa..f11d74e 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]