From 09acf5f7bcaa2cc975cb4dcadb5b9a5726fa5ee6 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Tue, 17 Dec 2024 17:56:25 +0000 Subject: [PATCH 1/2] Avoid a null pointer exception if there is a problem parsing a type. --- .../scala/tigerpython/utilities/scopes/ModuleLoader.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tpParser/shared/src/main/scala/tigerpython/utilities/scopes/ModuleLoader.scala b/tpParser/shared/src/main/scala/tigerpython/utilities/scopes/ModuleLoader.scala index f657e57..e5f7927 100644 --- a/tpParser/shared/src/main/scala/tigerpython/utilities/scopes/ModuleLoader.scala +++ b/tpParser/shared/src/main/scala/tigerpython/utilities/scopes/ModuleLoader.scala @@ -184,7 +184,9 @@ object ModuleLoader { if (item.contains('(')) { val b = if (curClass != null) PythonFunction.fromString(item, curClass, module.getFields) else BuiltinFunction.fromString(item, module.getFields) - curTarget.setField(b.name, b) + if (b != null) { + curTarget.setField(b.name, b) + } } else if (item != null && item != "") { if (item.startsWith("[")) { From 41cf47b9e2a9b3b58e3ce73c294b8934f46533c8 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Tue, 17 Dec 2024 17:56:45 +0000 Subject: [PATCH 2/2] Added some tests for parameter names in the autocomplete, which already pass. --- .../completer_params/params_module_example_1.py | 13 +++++++++++++ .../completer_params/params_module_example_2.py | 13 +++++++++++++ tpParser/shared/src/test/scala/TestCompleter.scala | 11 +++++++++++ 3 files changed, 37 insertions(+) create mode 100644 tpParser/shared/src/test/programs/completer_params/params_module_example_1.py create mode 100644 tpParser/shared/src/test/programs/completer_params/params_module_example_2.py diff --git a/tpParser/shared/src/test/programs/completer_params/params_module_example_1.py b/tpParser/shared/src/test/programs/completer_params/params_module_example_1.py new file mode 100644 index 0000000..d9d19fa --- /dev/null +++ b/tpParser/shared/src/test/programs/completer_params/params_module_example_1.py @@ -0,0 +1,13 @@ +# parent1.child1.shape1 +# class Shape: +# pos_x +# pos_y +# __init__(self, x, y) +# draw(self) +# extent(self) +# rotate_by(self, degrees) +# [Shape]make_shape() +# 49 +# degrees +from parent1.child1.shape1 import * +make_shape().rotate_by() diff --git a/tpParser/shared/src/test/programs/completer_params/params_module_example_2.py b/tpParser/shared/src/test/programs/completer_params/params_module_example_2.py new file mode 100644 index 0000000..1ad7900 --- /dev/null +++ b/tpParser/shared/src/test/programs/completer_params/params_module_example_2.py @@ -0,0 +1,13 @@ +# parent2.child2.shape2 +# class Shape: +# pos_x +# pos_y +# __init__(self, x, y) +# draw(self) +# extent(self) +# rotate_by(self, degrees) +# [Shape]make_shape(shape_type, shape_colour) +# 36 +# shape_type, shape_colour +from parent2.child2.shape2 import * +make_shape() diff --git a/tpParser/shared/src/test/scala/TestCompleter.scala b/tpParser/shared/src/test/scala/TestCompleter.scala index 8092f59..3220dc8 100644 --- a/tpParser/shared/src/test/scala/TestCompleter.scala +++ b/tpParser/shared/src/test/scala/TestCompleter.scala @@ -70,4 +70,15 @@ class TestCompleter extends FunSuite { val suggestions = completer.getNameFilter.getNameList("").mkString(";") assert(suggestions == expected_result) } + + for (fileName <- listAllFiles("completer_params")) + test("test program '%s'".format(getFileName(fileName))) { + val (pos, expected_result, text) = loadFromCompleterFile(fileName) + val completer = new Completer(fileName, text, pos) + val funcNameAtPos = text.drop(pos).takeWhile(_ != '(') + val params = completer.getNameFilter.getParams(funcNameAtPos) + assert(params == expected_result) + val extParams = completer.getNameFilter.getExtInfoList.filter(_.name == funcNameAtPos).map(_.parameters.mkString(", ")) + assert(extParams sameElements Array(expected_result)) + } }