nebius/SWE-bench-extra huggingface dataset:
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



Comments:

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()
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'
```

Comments:

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()