Starting from the current state, you could make ChatGPT much better programmer simply via brute-force approach:
1) ask it to generate (positive and negative) test cases first
2) ask it to review the test cases it wrote to make sure they fit the spec
3) ask it to produce an architecture of the program you want (you need to specifically ask it for writing modular code, consisting of small testable functions), fitting spec and test cases
4) ask it to write the tests for each function
5) ask it to find mistakes in the functions it wrote
6) run the functions against tests it wrote and present to it failures, asking to fix them (loop here until fixed)
7) run the e2e tests it wrote at the beginning and present mistakes to it, asking it to fix them
8) run the whole process in parallel multiple times, until one of them works
It's not pretty, it's not cheap and it's not super robust, but neither is the code written by majority of programmers. And I'm sure you could make it understand the code even better using some kind of evolutionary algorithms, by letting it play with interpreter.