Whole file
terryyin/lizard
The author described this change as “Fix func keyword usage in Golike structs and interfaces”. It counts as a record because the checks below fail on the code as it stood at 7b47f8885 and pass on 214288237, with nothing else changed between the two runs.
Projectterryyin/lizard
Fix saved2024-10-07
Sharing licenceMIT · LICENSE.txt
Change size+21 −0
What the code was meant to do, written into the code itself as a save note
Fix func keyword usage in Golike structs and interfaces
The change
| 13 | 13 | if token == self.FUNC_KEYWORD: | |
| 14 | 14 | self._state = self._function_name | |
| 15 | 15 | self.context.push_new_function('') | |
| 16 | + | elif token == 'type': | |
| 17 | + | self._state = self._type_definition | |
| 16 | 18 | elif token in '{': | |
| 17 | 19 | self.sub_state(self.statemachine_clone()) | |
| 18 | 20 | elif token in '}': | |
| 19 | 21 | self.statemachine_return() | |
| 22 | + | ||
| 23 | + | def _type_definition(self, token): | |
| 24 | + | self._state = self._after_type_name | |
| 25 | + | ||
| 26 | + | def _after_type_name(self, token): | |
| 27 | + | if token == 'struct': | |
| 28 | + | self._state = self._struct_definition | |
| 29 | + | elif token == 'interface': | |
| 30 | + | self._state = self._interface_definition | |
| 31 | + | else: | |
| 32 | + | self._state = self._state_global | |
| 33 | + | ||
| 34 | + | @CodeStateMachine.read_inside_brackets_then("{}", "_state_global") | |
| 35 | + | def _struct_definition(self, tokens): | |
| 36 | + | pass | |
| 37 | + | ||
| 38 | + | @CodeStateMachine.read_inside_brackets_then("{}", "_state_global") | |
| 39 | + | def _interface_definition(self, tokens): | |
| 40 | + | pass | |
| 20 | 41 | ||
| 21 | 42 | def _function_name(self, token): | |
| 22 | 43 | if token != '`': |
The check that tells the two apart
fail→pass·test/test_languages/testGo.py::Test_parser_for_Go::test_interface_with_func_followed_by_function_with_receiver
fail→pass·test/test_languages/testGo.py::Test_parser_for_Go::test_struct_with_func_followed_by_function_with_receiver
Check file test/test_languages/testGo.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it7b47f8885eb694e6ec82df21e024f2b5265ffba9
Broken version dated2024-04-25
Modulelizard_languages.golike
Units changedGoLikeStates
Fingerprint765b0cb7f166f834
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in terryyin/lizard
- 2026-08-08fix(java): do not report control structures as methods
- 2026-07-02HalsteadClassifier
- 2026-07-02fix(csv): emit columns for extensions with multiple FUNCTION_INFO fields
- 2026-06-15fix(golike): register generic functions with [...] type params
- 2026-06-15fix(java): enhance parsing of generic and qualified type names in anonymous classes
- 2026-06-11fix(script): stop a '#' comment continuing past a trailing backslash (#317)