Repository: robotpy/robotpy-cppheaderparser

Issue:
Another regression in 4.0.0
Following example fails using 4.0.0 and newer (but not with 3.3.0 and older):
```python
import CppHeaderParser

h = """
typedef C A;

class B
{
public:
   A aMethod();
}
"""
CppHeaderParser.CppHeader(h, "string")
```

Following exception is raised:
```bash
Traceback (most recent call last):
  File "ess.py", line 12, in <module>
    CppHeaderParser.CppHeader(h, "string")
  File "/home/thomas/miniconda3/envs/bindgen/lib/python3.7/site-packages/CppHeaderParser/CppHeaderParser.py", line 2981, in __init__
    self.finalize()
  File "/home/thomas/miniconda3/envs/bindgen/lib/python3.7/site-packages/CppHeaderParser/CppHeaderParser.py", line 1936, in finalize
    self.resolve_type(meth["rtnType"], rtnType)
  File "/home/thomas/miniconda3/envs/bindgen/lib/python3.7/site-packages/CppHeaderParser/CppHeaderParser.py", line 1551, in resolve_type
    result["typedefs"] += 1
KeyError: 'typedefs'
```

Discussion:

Patch:
diff --git a/CppHeaderParser/CppHeaderParser.py b/CppHeaderParser/CppHeaderParser.py
index 7b07900..cb8fda2 100644
--- a/CppHeaderParser/CppHeaderParser.py
+++ b/CppHeaderParser/CppHeaderParser.py
@@ -1957,6 +1957,7 @@ class _CppHeader(Resolver):
                     "static": 0,
                     "pointer": 0,
                     "reference": 0,
+                    "typedefs": 0,
                 }
                 self.resolve_type(meth["rtnType"], rtnType)
                 if not rtnType["unresolved"]:


Test patch:
diff --git a/test/test_CppHeaderParser.py b/test/test_CppHeaderParser.py
index a876d87..d3f54e7 100644
--- a/test/test_CppHeaderParser.py
+++ b/test/test_CppHeaderParser.py
@@ -3868,5 +3868,30 @@ template <class SomeType> class A {
         self.assertEqual(c["type"], "C")
 
 
+class MoreTypedef(unittest.TestCase):
+    def setUp(self):
+        self.cppHeader = CppHeaderParser.CppHeader(
+            """
+typedef C A;
+
+class B {
+public:
+  A aMethod();
+};
+""",
+            "string",
+        )
+
+    def test_fn(self):
+        c = self.cppHeader.classes["B"]
+        self.assertEqual("B", c["name"])
+
+        m = c["methods"]["public"][0]
+        self.assertEqual(m["name"], "aMethod")
+        self.assertEqual(m["rtnType"], "A")
+
+        self.assertEqual(self.cppHeader.typedefs["A"], "C")
+
+
 if __name__ == "__main__":
     unittest.main()