Repository: robotpy/robotpy-cppheaderparser

Issue:
Regression in 4.0.0
The following code works on 3.3.0 release but fails from 4.0.0 and later:

```python
import CppHeaderParser

h = """
template <class SomeType> class A {
 public:
  typedef B <SomeType> C;
  
  A();

 protected:
  C aCInstance;
};

"""
a = CppHeaderParser.CppHeader(h, "string")
print(a)
```

The error message is the following:
```bash
Traceback (most recent call last):
  File "ess.py", line 15, in <module>
    a = 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 1918, in finalize
    self.finalize_vars()
  File "/home/thomas/miniconda3/envs/bindgen/lib/python3.7/site-packages/CppHeaderParser/CppHeaderParser.py", line 1664, in finalize_vars
    var["raw_type"] = var["method"]["path"] + "::" + tag
KeyError: 'method'
```

Note that the issue comes from the last line ```C aCInstance;```. If type is changed to something else but C, string is parse correctly.

ping @rainman110



Discussion:

Patch:
diff --git a/CppHeaderParser/CppHeaderParser.py b/CppHeaderParser/CppHeaderParser.py
index 56739b0..7b07900 100644
--- a/CppHeaderParser/CppHeaderParser.py
+++ b/CppHeaderParser/CppHeaderParser.py
@@ -1685,7 +1685,7 @@ class Resolver(object):
 
                     elif nestedTypedef:
                         var["fundamental"] = is_fundamental(nestedTypedef)
-                        if not var["fundamental"]:
+                        if not var["fundamental"] and "method" in var:
                             var["raw_type"] = var["method"]["path"] + "::" + tag
 
                     else:


Test patch:
diff --git a/test/test_CppHeaderParser.py b/test/test_CppHeaderParser.py
index d23cb23..a876d87 100644
--- a/test/test_CppHeaderParser.py
+++ b/test/test_CppHeaderParser.py
@@ -3838,5 +3838,35 @@ class A : public B<int, int>::C {};
         )
 
 
+class NestedTypedef(unittest.TestCase):
+    def setUp(self):
+        self.cppHeader = CppHeaderParser.CppHeader(
+            """
+template <class SomeType> class A {
+ public:
+  typedef B <SomeType> C;
+  
+  A();
+
+ protected:
+  C aCInstance;
+};
+""",
+            "string",
+        )
+
+    def test_fn(self):
+        c = self.cppHeader.classes["A"]
+        self.assertEqual("A", c["name"])
+
+        self.assertEqual(0, len(c["properties"]["public"]))
+        self.assertEqual(1, len(c["properties"]["protected"]))
+        self.assertEqual(0, len(c["properties"]["private"]))
+
+        c = c["properties"]["protected"][0]
+        self.assertEqual(c["name"], "aCInstance")
+        self.assertEqual(c["type"], "C")
+
+
 if __name__ == "__main__":
     unittest.main()