Commit 021ea9a8 authored by Luca Bruno's avatar Luca Bruno

Fix symbol resolution for local constants

Fixes bug 649562.
parent 7abd9b1b
......@@ -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) {
......
......@@ -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 \
......
void main () {
{
const int a = 2;
}
SourceFunc f = () => {
const int b = 3;
return false;
};
}
......@@ -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);
......
......@@ -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) {
......
......@@ -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);
......
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