From 4bf3017c8c53e139ebb307bc501ab8f6e2ea68f6 Mon Sep 17 00:00:00 2001
From: Joel Bosveld <Joel.Bosveld@gmail.com>
Date: Thu, 26 Feb 2009 20:36:51 +0900
Subject: [PATCH] Warn if attempting to get wrong type from CompOption::Value

---
 src/option.cpp |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/src/option.cpp b/src/option.cpp
index c8fcd2f..8779244 100644
--- a/src/option.cpp
+++ b/src/option.cpp
@@ -190,7 +190,10 @@ bool
 CompOption::Value::b ()
 {
     if (priv->type != CompOption::TypeBool)
+    {
+	compLogMessage("core", CompLogLevelWarn, "CompOption::Value not a bool");
 	return false;
+    }
     return priv->value.b;
 }
 
@@ -198,7 +201,10 @@ int
 CompOption::Value::i ()
 {
     if (priv->type != CompOption::TypeInt)
+    {
+	compLogMessage("core", CompLogLevelWarn, "CompOption::Value not an int");
 	return 0;
+    }
     return priv->value.i;
 }
 
@@ -206,7 +212,10 @@ float
 CompOption::Value::f ()
 {
     if (priv->type != CompOption::TypeFloat)
+    {
+	compLogMessage("core", CompLogLevelWarn, "CompOption::Value not a float");
 	return 0.0;
+    }
     return priv->value.f;
 }
 
@@ -216,37 +225,54 @@ unsigned short*
 CompOption::Value::c ()
 {
     if (priv->type != CompOption::TypeColor)
+    {
+	compLogMessage("core", CompLogLevelWarn, "CompOption::Value not a color");
 	return reinterpret_cast<unsigned short *> (&defaultColor);
+    }
     return priv->value.c;
 }
 
 CompString
 CompOption::Value::s ()
 {
+    if (priv->type != CompOption::TypeString)
+	compLogMessage("core", CompLogLevelWarn, "CompOption::Value not a string");
     return priv->string;
 }
 
 CompMatch &
 CompOption::Value::match ()
 {
+    if (priv->type != CompOption::TypeMatch)
+	compLogMessage("core", CompLogLevelWarn, "CompOption::Value not a match");
     return priv->match;
 }
 
 CompAction &
 CompOption::Value::action ()
 {
+    if (priv->type != CompOption::TypeAction &&
+        priv->type != CompOption::TypeKey &&
+        priv->type != CompOption::TypeButton &&
+        priv->type != CompOption::TypeEdge &&
+        priv->type != CompOption::TypeBell)
+	compLogMessage("core", CompLogLevelWarn, "CompOption::Value not an action");
     return priv->action;
 }
 
 CompOption::Type
 CompOption::Value::listType ()
 {
+    if (priv->type != CompOption::TypeList)
+	compLogMessage("core", CompLogLevelWarn, "CompOption::Value not a list");
     return priv->listType;
 }
 
 CompOption::Value::Vector &
 CompOption::Value::list ()
 {
+    if (priv->type != CompOption::TypeList)
+	compLogMessage("core", CompLogLevelWarn, "CompOption::Value not a list");
     return priv->list;
 }
 
-- 
1.6.0.6

