THRIFT-5286: Fix Lua library readBool() in TCompactProtocol
Client: Lua
Patch: Jeffrey Han

This closes #2252
diff --git a/lib/lua/TCompactProtocol.lua b/lib/lua/TCompactProtocol.lua
index ca488dc..0ebccac 100644
--- a/lib/lua/TCompactProtocol.lua
+++ b/lib/lua/TCompactProtocol.lua
@@ -176,7 +176,6 @@
   if bool then
     value = TCompactType.COMPACT_BOOLEAN_TRUE
   end
-  print(value,self.booleanFieldPending,self.booleanFieldId)
   if self.booleanFieldPending then
     self:writeFieldBeginInternal(self.booleanFieldName, TType.BOOL, self.booleanFieldId, value)
     self.booleanFieldPending = false
@@ -293,17 +292,20 @@
   if ttype == TType.STOP then
     return nil, ttype, 0
   end
-  -- mask off the 4 MSB of the type header. it could contain a field id delta.
-  local modifier = libluabitwise.shiftr(libluabitwise.band(field_and_ttype, 0xf0), 4)
+  local modifier = libluabitwise.shiftr(field_and_ttype, 4)
   local id = 0
   if modifier == 0 then
     id = self:readI16()
   else
     id = self.lastFieldId + modifier
   end
-  if ttype == TType.BOOL then
-    boolValue = libluabitwise.band(field_and_ttype, 0x0f) == TCompactType.COMPACT_BOOLEAN_TRUE
-    boolValueIsNotNull = true
+  local type = libluabitwise.band(field_and_ttype, 0x0f)
+  if type == TCompactType.COMPACT_BOOLEAN_TRUE then
+    self.boolValue = true
+    self.boolValueIsNotNull = true
+  elseif type == TCompactType.COMPACT_BOOLEAN_FALSE then
+    self.boolValue = false
+    self.boolValueIsNotNull = true
   end
   self.lastFieldId = id
   return nil, ttype, id
@@ -350,9 +352,9 @@
 end
 
 function TCompactProtocol:readBool()
-  if boolValueIsNotNull then
-    boolValueIsNotNull = true
-    return boolValue
+  if self.boolValueIsNotNull then
+    self.boolValueIsNotNull = false
+    return self.boolValue
   end
   local val = self:readSignByte()
   if val == TCompactType.COMPACT_BOOLEAN_TRUE then