summaryrefslogtreecommitdiff
path: root/vala/valaswitchstatement.vala
diff options
context:
space:
mode:
authorLuca Bruno <lethalman88@gmail.com>2010-03-08 23:36:51 +0100
committerJürg Billeter <j@bitron.ch>2010-03-21 23:33:41 +0100
commitfea88bd2074321eb20881357984290e94fb31e72 (patch)
treedcc9bc199f5a43c415f6e25b3772e651b020bc41 /vala/valaswitchstatement.vala
parent073f3eaf718ad51776dabf21c408a28622f7d421 (diff)
downloadvala-fea88bd2074321eb20881357984290e94fb31e72.tar.gz
Report error on duplicate switch label
Fixes bug 572556.
Diffstat (limited to 'vala/valaswitchstatement.vala')
-rw-r--r--vala/valaswitchstatement.vala15
1 files changed, 15 insertions, 0 deletions
diff --git a/vala/valaswitchstatement.vala b/vala/valaswitchstatement.vala
index eb038bbf4..00a8b8ffa 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 ());
}