[vala] Report error on duplicate switch label
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Report error on duplicate switch label
- Date: Sun, 21 Mar 2010 22:34:26 +0000 (UTC)
commit fea88bd2074321eb20881357984290e94fb31e72
Author: Luca Bruno <lethalman88 gmail com>
Date: Mon Mar 8 23:36:51 2010 +0100
Report error on duplicate switch label
Fixes bug 572556.
vala/valaswitchstatement.vala | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)
---
diff --git a/vala/valaswitchstatement.vala b/vala/valaswitchstatement.vala
index eb038bb..00a8b8f 100644
--- a/vala/valaswitchstatement.vala
+++ b/vala/valaswitchstatement.vala
@@ -116,9 +116,24 @@ public class Vala.SwitchStatement : CodeNode, Statement {
// ensure that possibly owned (string) expression stays alive
expression.target_type = expression.value_type.copy ();
+ var labelset = new HashSet<string> (str_hash, str_equal);
foreach (SwitchSection section in sections) {
section.check (analyzer);
+ // check for duplicate literal case labels
+ // FIXME: make it work for all constant expressions
+ foreach (SwitchLabel label in section.get_labels ()) {
+ string? value = null;
+ if (label.expression is StringLiteral) {
+ value = ((StringLiteral)label.expression).eval ();
+ } else if (label.expression is Literal) {
+ value = ((Literal)label.expression).to_string ();
+ }
+
+ if (value != null && !labelset.add (value)) {
+ Report.error (label.expression.source_reference, "Switch statement already contains this label");
+ }
+ }
add_error_types (section.get_error_types ());
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]