[vala] Check if the constants used as switch labels are duplicated



commit 6e216346176ee05a285803f70d17185a0c69a6d9
Author: Luca Bruno <lucabru src gnome org>
Date:   Mon Aug 15 21:03:12 2011 +0200

    Check if the constants used as switch labels are duplicated
    
    Fixes bug 656481.

 vala/valaswitchstatement.vala |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)
---
diff --git a/vala/valaswitchstatement.vala b/vala/valaswitchstatement.vala
index 12ad04b..c583f8d 100644
--- a/vala/valaswitchstatement.vala
+++ b/vala/valaswitchstatement.vala
@@ -123,18 +123,21 @@ public class Vala.SwitchStatement : CodeNode, Statement {
 			section.check (context);
 
 			// 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)) {
-					error = true;
-					Report.error (label.expression.source_reference, "Switch statement already contains this label");
+				if (label.expression != null) {
+					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 ();
+					} else if (label.expression.is_constant ()) {
+						value = label.expression.to_string ();
+					}
+
+					if (value != null && !labelset.add (value)) {
+						error = true;
+						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]