From 26c01bd639b31ae2c3662a911b22aa8739db1b62 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Tue, 19 Sep 2023 14:53:45 +0200 Subject: [PATCH 01/11] test: cannot refer to something that's not an annotation in annotation call --- .../scoping/annotation calls/on annotation/main.sdstest | 4 ++++ .../scoping/annotation calls/on attribute/main.sdstest | 4 ++++ .../resources/scoping/annotation calls/on class/main.sdstest | 4 ++++ .../scoping/annotation calls/on enum variant/main.sdstest | 4 ++++ tests/resources/scoping/annotation calls/on enum/main.sdstest | 4 ++++ .../scoping/annotation calls/on function/main.sdstest | 4 ++++ .../resources/scoping/annotation calls/on module/main.sdstest | 4 ++++ .../scoping/annotation calls/on parameter/main.sdstest | 4 ++++ .../scoping/annotation calls/on pipeline/main.sdstest | 4 ++++ .../resources/scoping/annotation calls/on result/main.sdstest | 4 ++++ .../scoping/annotation calls/on segment/main.sdstest | 4 ++++ .../scoping/annotation calls/on type parameter/main.sdstest | 4 ++++ 12 files changed, 48 insertions(+) diff --git a/tests/resources/scoping/annotation calls/on annotation/main.sdstest b/tests/resources/scoping/annotation calls/on annotation/main.sdstest index d9a19539c..c5e48425c 100644 --- a/tests/resources/scoping/annotation calls/on annotation/main.sdstest +++ b/tests/resources/scoping/annotation calls/on annotation/main.sdstest @@ -8,8 +8,12 @@ annotation »Before« // $TEST$ references after @»After« // $TEST$ unresolved +@»NotAnAnnotation« +// $TEST$ unresolved @»Unresolved« annotation MyAnnotation // $TEST$ target after annotation »After« + +class NotAnAnnotation diff --git a/tests/resources/scoping/annotation calls/on attribute/main.sdstest b/tests/resources/scoping/annotation calls/on attribute/main.sdstest index aed38fa55..6a2de1286 100644 --- a/tests/resources/scoping/annotation calls/on attribute/main.sdstest +++ b/tests/resources/scoping/annotation calls/on attribute/main.sdstest @@ -9,9 +9,13 @@ class MyClass { // $TEST$ references after @»After« // $TEST$ unresolved + @»NotAnAnnotation« + // $TEST$ unresolved @»Unresolved« attr myAttribute: Int } // $TEST$ target after annotation »After« + +class NotAnAnnotation diff --git a/tests/resources/scoping/annotation calls/on class/main.sdstest b/tests/resources/scoping/annotation calls/on class/main.sdstest index e28243da1..dd1a47dbc 100644 --- a/tests/resources/scoping/annotation calls/on class/main.sdstest +++ b/tests/resources/scoping/annotation calls/on class/main.sdstest @@ -8,8 +8,12 @@ annotation »Before« // $TEST$ references after @»After« // $TEST$ unresolved +@»NotAnAnnotation« +// $TEST$ unresolved @»Unresolved« class MyClass // $TEST$ target after annotation »After« + +class NotAnAnnotation diff --git a/tests/resources/scoping/annotation calls/on enum variant/main.sdstest b/tests/resources/scoping/annotation calls/on enum variant/main.sdstest index 98187558e..3e29f8aeb 100644 --- a/tests/resources/scoping/annotation calls/on enum variant/main.sdstest +++ b/tests/resources/scoping/annotation calls/on enum variant/main.sdstest @@ -9,9 +9,13 @@ enum MyEnum { // $TEST$ references after @»After« // $TEST$ unresolved + @»NotAnAnnotation« + // $TEST$ unresolved @»Unresolved« MyEnumVariant } // $TEST$ target after annotation »After« + +class NotAnAnnotation diff --git a/tests/resources/scoping/annotation calls/on enum/main.sdstest b/tests/resources/scoping/annotation calls/on enum/main.sdstest index 4441b46e4..b213ee1ed 100644 --- a/tests/resources/scoping/annotation calls/on enum/main.sdstest +++ b/tests/resources/scoping/annotation calls/on enum/main.sdstest @@ -8,8 +8,12 @@ annotation »Before« // $TEST$ references after @»After« // $TEST$ unresolved +@»NotAnAnnotation« +// $TEST$ unresolved @»Unresolved« enum MyEnum // $TEST$ target after annotation »After« + +class NotAnAnnotation diff --git a/tests/resources/scoping/annotation calls/on function/main.sdstest b/tests/resources/scoping/annotation calls/on function/main.sdstest index 025c439d5..6bfc169dc 100644 --- a/tests/resources/scoping/annotation calls/on function/main.sdstest +++ b/tests/resources/scoping/annotation calls/on function/main.sdstest @@ -8,8 +8,12 @@ annotation »Before« // $TEST$ references after @»After« // $TEST$ unresolved +@»NotAnAnnotation« +// $TEST$ unresolved @»Unresolved« fun myFunction() // $TEST$ target after annotation »After« + +class NotAnAnnotation diff --git a/tests/resources/scoping/annotation calls/on module/main.sdstest b/tests/resources/scoping/annotation calls/on module/main.sdstest index 768322311..17dfcaf16 100644 --- a/tests/resources/scoping/annotation calls/on module/main.sdstest +++ b/tests/resources/scoping/annotation calls/on module/main.sdstest @@ -1,9 +1,13 @@ // $TEST$ references annotation @»MyAnnotation« // $TEST$ unresolved +@»NotAnAnnotation« +// $TEST$ unresolved @»Unresolved« package test.scoping.annotationCalls.onModule // $TEST$ target annotation annotation »MyAnnotation« + +class NotAnAnnotation diff --git a/tests/resources/scoping/annotation calls/on parameter/main.sdstest b/tests/resources/scoping/annotation calls/on parameter/main.sdstest index 5990b98c0..3cee1fe6d 100644 --- a/tests/resources/scoping/annotation calls/on parameter/main.sdstest +++ b/tests/resources/scoping/annotation calls/on parameter/main.sdstest @@ -9,9 +9,13 @@ fun myFunction( // $TEST$ references after @»After« // $TEST$ unresolved + @»NotAnAnnotation« + // $TEST$ unresolved @»Unresolved« myParameter: Int ) // $TEST$ target after annotation »After« + +class NotAnAnnotation diff --git a/tests/resources/scoping/annotation calls/on pipeline/main.sdstest b/tests/resources/scoping/annotation calls/on pipeline/main.sdstest index 40f1f5171..61dfc90ed 100644 --- a/tests/resources/scoping/annotation calls/on pipeline/main.sdstest +++ b/tests/resources/scoping/annotation calls/on pipeline/main.sdstest @@ -8,8 +8,12 @@ annotation »Before« // $TEST$ references after @»After« // $TEST$ unresolved +@»NotAnAnnotation« +// $TEST$ unresolved @»Unresolved« pipeline myPipeline {} // $TEST$ target after annotation »After« + +class NotAnAnnotation diff --git a/tests/resources/scoping/annotation calls/on result/main.sdstest b/tests/resources/scoping/annotation calls/on result/main.sdstest index 1bd82e4e3..5e9a9ca3c 100644 --- a/tests/resources/scoping/annotation calls/on result/main.sdstest +++ b/tests/resources/scoping/annotation calls/on result/main.sdstest @@ -9,9 +9,13 @@ fun myFunction() -> ( // $TEST$ references after @»After« // $TEST$ unresolved + @»NotAnAnnotation« + // $TEST$ unresolved @»Unresolved« myResult: Int ) // $TEST$ target after annotation »After« + +class NotAnAnnotation diff --git a/tests/resources/scoping/annotation calls/on segment/main.sdstest b/tests/resources/scoping/annotation calls/on segment/main.sdstest index 59d4c99e4..b79f45d6a 100644 --- a/tests/resources/scoping/annotation calls/on segment/main.sdstest +++ b/tests/resources/scoping/annotation calls/on segment/main.sdstest @@ -8,8 +8,12 @@ annotation »Before« // $TEST$ references after @»After« // $TEST$ unresolved +@»NotAnAnnotation« +// $TEST$ unresolved @»Unresolved« segment mySegment() {} // $TEST$ target after annotation »After« + +class NotAnAnnotation diff --git a/tests/resources/scoping/annotation calls/on type parameter/main.sdstest b/tests/resources/scoping/annotation calls/on type parameter/main.sdstest index 5e400106d..e57c694c3 100644 --- a/tests/resources/scoping/annotation calls/on type parameter/main.sdstest +++ b/tests/resources/scoping/annotation calls/on type parameter/main.sdstest @@ -9,9 +9,13 @@ fun myFunction< // $TEST$ references after @»After« // $TEST$ unresolved + @»NotAnAnnotation« + // $TEST$ unresolved @»Unresolved« MyTypeParameter >() // $TEST$ target after annotation »After« + +class NotAnAnnotation From c3b234cf74b418839f987aa17421d8e73f989651 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Tue, 19 Sep 2023 15:00:49 +0200 Subject: [PATCH 02/11] test: cannot refer to something that's not a type parameter in type parameter constraint --- .../type parameter constraints/in annotation/main.sdstest | 5 +++++ .../in enum variant in global enum/main.sdstest | 5 +++++ .../in enum variant in nested enum/main.sdstest | 5 +++++ .../type parameter constraints/in global class/main.sdstest | 5 +++++ .../in global function/main.sdstest | 5 +++++ .../type parameter constraints/in method/main.sdstest | 6 +++++- .../type parameter constraints/in nested class/main.sdstest | 6 +++++- 7 files changed, 35 insertions(+), 2 deletions(-) diff --git a/tests/resources/scoping/type parameter constraints/in annotation/main.sdstest b/tests/resources/scoping/type parameter constraints/in annotation/main.sdstest index 1586f2b2b..7a01d31aa 100644 --- a/tests/resources/scoping/type parameter constraints/in annotation/main.sdstest +++ b/tests/resources/scoping/type parameter constraints/in annotation/main.sdstest @@ -9,8 +9,13 @@ annotation MyAnnotation where { // $TEST$ unresolved »After« sub Int, + // $TEST$ unresolved + »NotATypeParameter« sub Int, + // $TEST$ unresolved »Unresolved« sub Int } fun myFunction2() + +class NotATypeParameter diff --git a/tests/resources/scoping/type parameter constraints/in enum variant in global enum/main.sdstest b/tests/resources/scoping/type parameter constraints/in enum variant in global enum/main.sdstest index 36d541d40..000e229f3 100644 --- a/tests/resources/scoping/type parameter constraints/in enum variant in global enum/main.sdstest +++ b/tests/resources/scoping/type parameter constraints/in enum variant in global enum/main.sdstest @@ -22,6 +22,9 @@ enum MyEnum { // $TEST$ unresolved »AfterEnum« sub Int, + // $TEST$ unresolved + »NotATypeParameter« sub Int, + // $TEST$ unresolved »Unresolved« sub Int } @@ -30,3 +33,5 @@ enum MyEnum { } fun myFunction2() + +class NotATypeParameter diff --git a/tests/resources/scoping/type parameter constraints/in enum variant in nested enum/main.sdstest b/tests/resources/scoping/type parameter constraints/in enum variant in nested enum/main.sdstest index 51923e792..237f3d63f 100644 --- a/tests/resources/scoping/type parameter constraints/in enum variant in nested enum/main.sdstest +++ b/tests/resources/scoping/type parameter constraints/in enum variant in nested enum/main.sdstest @@ -31,6 +31,9 @@ class MyClass<»Container«, Overridden> { // $TEST$ unresolved »AfterEnum« sub Int, + // $TEST$ unresolved + »NotATypeParameter« sub Int, + // $TEST$ unresolved »Unresolved« sub Int } @@ -40,3 +43,5 @@ class MyClass<»Container«, Overridden> { } fun myFunction2() + +class NotATypeParameter diff --git a/tests/resources/scoping/type parameter constraints/in global class/main.sdstest b/tests/resources/scoping/type parameter constraints/in global class/main.sdstest index 640c21158..0928121c1 100644 --- a/tests/resources/scoping/type parameter constraints/in global class/main.sdstest +++ b/tests/resources/scoping/type parameter constraints/in global class/main.sdstest @@ -13,8 +13,13 @@ class MyClass<»Own«> where { // $TEST$ unresolved »After« sub Int, + // $TEST$ unresolved + »NotATypeParameter« sub Int, + // $TEST$ unresolved »Unresolved« sub Int } fun myFunction2() + +class NotATypeParameter diff --git a/tests/resources/scoping/type parameter constraints/in global function/main.sdstest b/tests/resources/scoping/type parameter constraints/in global function/main.sdstest index 803afd004..cbb53091b 100644 --- a/tests/resources/scoping/type parameter constraints/in global function/main.sdstest +++ b/tests/resources/scoping/type parameter constraints/in global function/main.sdstest @@ -13,8 +13,13 @@ fun myFunction2<»Own«>() where { // $TEST$ unresolved »After« sub Int, + // $TEST$ unresolved + »NotATypeParameter« sub Int, + // $TEST$ unresolved »Unresolved« sub Int } fun myFunction3() + +class NotATypeParameter diff --git a/tests/resources/scoping/type parameter constraints/in method/main.sdstest b/tests/resources/scoping/type parameter constraints/in method/main.sdstest index 0ebd8a9c8..057b0a3c4 100644 --- a/tests/resources/scoping/type parameter constraints/in method/main.sdstest +++ b/tests/resources/scoping/type parameter constraints/in method/main.sdstest @@ -30,6 +30,9 @@ class MyClass1<»Container«, Overridden> { // $TEST$ unresolved »AfterGlobal« sub Int, + // $TEST$ unresolved + »NotATypeParameter« sub Int, + // $TEST$ unresolved »Unresolved« sub Int } @@ -37,5 +40,6 @@ class MyClass1<»Container«, Overridden> { fun myFunction5() } - fun myFunction5() + +class NotATypeParameter diff --git a/tests/resources/scoping/type parameter constraints/in nested class/main.sdstest b/tests/resources/scoping/type parameter constraints/in nested class/main.sdstest index 0af703364..ec0d152fd 100644 --- a/tests/resources/scoping/type parameter constraints/in nested class/main.sdstest +++ b/tests/resources/scoping/type parameter constraints/in nested class/main.sdstest @@ -30,6 +30,9 @@ class MyClass1<»Container«, Overridden> { // $TEST$ unresolved »AfterGlobal« sub Int, + // $TEST$ unresolved + »NotATypeParameter« sub Int, + // $TEST$ unresolved »Unresolved« sub Int } @@ -37,5 +40,6 @@ class MyClass1<»Container«, Overridden> { fun myFunction3() } - fun myFunction4() + +class NotATypeParameter From 8c82c0d8297f77e6367d63e0bddb88f1e36d13a8 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Tue, 19 Sep 2023 15:01:47 +0200 Subject: [PATCH 03/11] test: cannot refer to something that's not a result in yield --- tests/resources/scoping/yields/in pipeline/main.sdstest | 5 +++++ tests/resources/scoping/yields/in segment/main.sdstest | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/tests/resources/scoping/yields/in pipeline/main.sdstest b/tests/resources/scoping/yields/in pipeline/main.sdstest index 217f68d20..7de32cb4b 100644 --- a/tests/resources/scoping/yields/in pipeline/main.sdstest +++ b/tests/resources/scoping/yields/in pipeline/main.sdstest @@ -9,8 +9,13 @@ pipeline myPipeline { // $TEST$ unresolved yield »after« = 1; + // $TEST$ unresolved + yield »NotAResult« = 1; + // $TEST$ unresolved yield »unresolved« = 1; } segment mySegment2() -> after: Int {} + +class NotAResult diff --git a/tests/resources/scoping/yields/in segment/main.sdstest b/tests/resources/scoping/yields/in segment/main.sdstest index 289c465de..9369df4c0 100644 --- a/tests/resources/scoping/yields/in segment/main.sdstest +++ b/tests/resources/scoping/yields/in segment/main.sdstest @@ -15,8 +15,13 @@ segment mySegment() -> ( // $TEST$ unresolved yield »after« = 1; + // $TEST$ unresolved + yield »NotAResult« = 1; + // $TEST$ unresolved yield »unresolved« = 1; } segment mySegment2() -> after: Int {} + +class NotAResult From d4ed5dd92bacac0dace0fa190d47990efa40e38a Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Tue, 19 Sep 2023 15:42:02 +0200 Subject: [PATCH 04/11] test: scoping for named types to type parameters --- .../main.sdstest | 32 ++++++++++ .../main.sdstest | 42 ++++++++++++ .../in global class/main.sdstest | 32 ++++++++++ .../in global function/main.sdstest | 32 ++++++++++ .../to type parameter/in method/main.sdstest | 64 +++++++++++++++++++ .../in nested class/main.sdstest | 64 +++++++++++++++++++ 6 files changed, 266 insertions(+) create mode 100644 tests/resources/scoping/named types/to type parameter/in enum variant in global enum/main.sdstest create mode 100644 tests/resources/scoping/named types/to type parameter/in enum variant in nested enum/main.sdstest create mode 100644 tests/resources/scoping/named types/to type parameter/in global class/main.sdstest create mode 100644 tests/resources/scoping/named types/to type parameter/in global function/main.sdstest create mode 100644 tests/resources/scoping/named types/to type parameter/in method/main.sdstest create mode 100644 tests/resources/scoping/named types/to type parameter/in nested class/main.sdstest diff --git a/tests/resources/scoping/named types/to type parameter/in enum variant in global enum/main.sdstest b/tests/resources/scoping/named types/to type parameter/in enum variant in global enum/main.sdstest new file mode 100644 index 000000000..ecf16c635 --- /dev/null +++ b/tests/resources/scoping/named types/to type parameter/in enum variant in global enum/main.sdstest @@ -0,0 +1,32 @@ +package test.scoping.namedTypes.toTypeParameter.inEnumVariantInGlobalEnum + +fun myFunction1() + +enum MyEnum { + MyEnumVariant1 + + // $TEST$ target own + MyEnumVariant2<»Own«>( + // $TEST$ references own + a: »Own«, + + // $TEST$ unresolved + b: »BeforeEnumVariant«, + + // $TEST$ unresolved + c: »AfterEnumVariant«, + + // $TEST$ unresolved + d: »BeforeEnum«, + + // $TEST$ unresolved + e: »AfterEnum«, + + // $TEST$ unresolved + f: »Unresolved« + ) + + MyEnumVariant3 +} + +fun myFunction2() diff --git a/tests/resources/scoping/named types/to type parameter/in enum variant in nested enum/main.sdstest b/tests/resources/scoping/named types/to type parameter/in enum variant in nested enum/main.sdstest new file mode 100644 index 000000000..9cf59b37d --- /dev/null +++ b/tests/resources/scoping/named types/to type parameter/in enum variant in nested enum/main.sdstest @@ -0,0 +1,42 @@ +package test.scoping.namedTypes.toTypeParameter.inEnumVariantInNestedEnum + +fun myFunction1() + +// $TEST$ target container +class MyClass<»Container«, Overridden> { + enum MyEnum { + MyEnumVariant1 + + // $TEST$ target own + // $TEST$ target overridden + MyEnumVariant2<»Own«, »Overridden«>( + // $TEST$ references own + a: »Own«, + + // $TEST$ references overridden + b: »Overridden«, + + // $TEST$ references container + c: »Container«, + + // $TEST$ unresolved + d: »BeforeEnumVariant«, + + // $TEST$ unresolved + e: »AfterEnumVariant«, + + // $TEST$ unresolved + f: »BeforeEnum«, + + // $TEST$ unresolved + g: »AfterEnum«, + + // $TEST$ unresolved + h: »Unresolved« + ) + + MyEnumVariant3 + } +} + +fun myFunction2() diff --git a/tests/resources/scoping/named types/to type parameter/in global class/main.sdstest b/tests/resources/scoping/named types/to type parameter/in global class/main.sdstest new file mode 100644 index 000000000..dc5bc01c6 --- /dev/null +++ b/tests/resources/scoping/named types/to type parameter/in global class/main.sdstest @@ -0,0 +1,32 @@ +package test.scoping.namedTypes.toTypeParameter.inGlobalClass + +fun myFunction1() + +// $TEST$ target own +class MyClass<»Own«>( + // $TEST$ references own + a: »Own«, + + // $TEST$ unresolved + b: »Before«, + + // $TEST$ unresolved + c: »After«, + + // $TEST$ unresolved + d: »Unresolved« +) { + // $TEST$ references own + attr z: »Own« + + // $TEST$ unresolved + attr y: »Before« + + // $TEST$ unresolved + attr x: »After« + + // $TEST$ unresolved + attr w: »Unresolved« +} + +fun myFunction2() diff --git a/tests/resources/scoping/named types/to type parameter/in global function/main.sdstest b/tests/resources/scoping/named types/to type parameter/in global function/main.sdstest new file mode 100644 index 000000000..282f31bb2 --- /dev/null +++ b/tests/resources/scoping/named types/to type parameter/in global function/main.sdstest @@ -0,0 +1,32 @@ +package test.scoping.namedTypes.toTypeParameter.inGlobalFunction + +fun myFunction1() + +// $TEST$ target own +fun myFunction2<»Own«>( + // $TEST$ references own + a: »Own«, + + // $TEST$ unresolved + b: »Before«, + + // $TEST$ unresolved + c: »After«, + + // $TEST$ unresolved + d: »Unresolved« +) -> ( + // $TEST$ references own + z: »Own«, + + // $TEST$ unresolved + y: »Before«, + + // $TEST$ unresolved + x: »After«, + + // $TEST$ unresolved + w: »Unresolved« +) + +fun myFunction3() diff --git a/tests/resources/scoping/named types/to type parameter/in method/main.sdstest b/tests/resources/scoping/named types/to type parameter/in method/main.sdstest new file mode 100644 index 000000000..c1a75ba21 --- /dev/null +++ b/tests/resources/scoping/named types/to type parameter/in method/main.sdstest @@ -0,0 +1,64 @@ +package test.scoping.namedTypes.toTypeParameter.inMethod + +fun myFunction1() + +// $TEST$ target container +class MyClass1<»Container«, Overridden> { + fun myFunction2() + + // $TEST$ target own + // $TEST$ target overridden + fun myFunction3<»Own«, »Overridden«>( + // $TEST$ references own + a: »Own«, + + // $TEST$ references overridden + b: »Overridden«, + + // $TEST$ references container + c: »Container«, + + // $TEST$ unresolved + d: »BeforeMember«, + + // $TEST$ unresolved + e: »AfterMember«, + + // $TEST$ unresolved + g: »BeforeGlobal«, + + // $TEST$ unresolved + h: »AfterGlobal«, + + // $TEST$ unresolved + i: »Unresolved« + ) -> ( + // $TEST$ references own + z: »Own«, + + // $TEST$ references overridden + y: »Overridden«, + + // $TEST$ references container + x: »Container«, + + // $TEST$ unresolved + w: »BeforeMember«, + + // $TEST$ unresolved + v: »AfterMember«, + + // $TEST$ unresolved + u: »BeforeGlobal«, + + // $TEST$ unresolved + t: »AfterGlobal«, + + // $TEST$ unresolved + s: »Unresolved« + ) + + fun myFunction5() +} + +fun myFunction5() diff --git a/tests/resources/scoping/named types/to type parameter/in nested class/main.sdstest b/tests/resources/scoping/named types/to type parameter/in nested class/main.sdstest new file mode 100644 index 000000000..f029e5165 --- /dev/null +++ b/tests/resources/scoping/named types/to type parameter/in nested class/main.sdstest @@ -0,0 +1,64 @@ +package test.scoping.namedTypes.toTypeParameter.inNestedClass + +fun myFunction1() + +// $TEST$ target container +class MyClass1<»Container«, Overridden> { + fun myFunction2() + + // $TEST$ target own + // $TEST$ target overridden + class MyClass2<»Own«, »Overridden«>( + // $TEST$ references own + a: »Own«, + + // $TEST$ references overridden + b: »Overridden«, + + // $TEST$ references container + c: »Container«, + + // $TEST$ unresolved + d: »BeforeMember«, + + // $TEST$ unresolved + e: »AfterMember«, + + // $TEST$ unresolved + f: »BeforeGlobal«, + + // $TEST$ unresolved + g: »AfterGlobal«, + + // $TEST$ unresolved + h: »Unresolved« + ) { + // $TEST$ references own + attr z: »Own« + + // $TEST$ references overridden + attr y: »Overridden« + + // $TEST$ references container + attr x: »Container« + + // $TEST$ unresolved + attr w: »BeforeMember« + + // $TEST$ unresolved + attr v: »AfterMember« + + // $TEST$ unresolved + attr u: »BeforeGlobal« + + // $TEST$ unresolved + attr t: »AfterGlobal« + + // $TEST$ unresolved + attr s: »Unresolved« + } + + fun myFunction3() +} + +fun myFunction4() From 79815296684e5ff526b9dc76d4b0816967e4d31c Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Tue, 19 Sep 2023 16:32:16 +0200 Subject: [PATCH 05/11] test: scoping other named types --- .../main.sdstest | 53 +++++++++++++++++++ .../main.sdstest | 41 ++++++++++++++ .../main.sdstest | 49 +++++++++++++++++ .../named types/to global class/main.sdstest | 18 +++++++ .../named types/to global enum/main.sdstest | 18 +++++++ .../named types/to nested class/main.sdstest | 32 +++++++++++ .../named types/to nested enum/main.sdstest | 32 +++++++++++ .../main.sdstest | 6 +++ 8 files changed, 249 insertions(+) create mode 100644 tests/resources/scoping/named types/to containing named type declaration/main.sdstest create mode 100644 tests/resources/scoping/named types/to enum variant in global enum/main.sdstest create mode 100644 tests/resources/scoping/named types/to enum variant in nested enum/main.sdstest create mode 100644 tests/resources/scoping/named types/to global class/main.sdstest create mode 100644 tests/resources/scoping/named types/to global enum/main.sdstest create mode 100644 tests/resources/scoping/named types/to nested class/main.sdstest create mode 100644 tests/resources/scoping/named types/to nested enum/main.sdstest create mode 100644 tests/resources/scoping/named types/to something other than named type declaration/main.sdstest diff --git a/tests/resources/scoping/named types/to containing named type declaration/main.sdstest b/tests/resources/scoping/named types/to containing named type declaration/main.sdstest new file mode 100644 index 000000000..c995fc703 --- /dev/null +++ b/tests/resources/scoping/named types/to containing named type declaration/main.sdstest @@ -0,0 +1,53 @@ +package test.scoping.namedTypes.toContainingNamedTypeDeclaration + +// $TEST$ target outerClass +class »MyClass«( + // $TEST$ references outerClass + p: »MyClass« +) { + // $TEST$ references outerClass + attr a: »MyClass« + + // $TEST$ unresolved + attr b: »MyEnum« + + fun f( + // $TEST$ references outerClass + p: »MyClass« + ) -> ( + // $TEST$ references outerClass + r: »MyClass« + ) + + // $TEST$ target enum + enum »MyEnum« { + // $TEST$ target variant + »MyEnumVariant«( + // $TEST$ references outerClass + p1: »MyClass«, + + // $TEST$ references enum + p2: »MyEnum«, + + // $TEST$ references variant + p3: »MyEnumVariant«, + ) + } + + // $TEST$ target innerClass + class »MyClass«( + // $TEST$ references innerClass + p: »MyClass« + ) { + // $TEST$ references innerClass + attr a: »MyClass« + + fun f( + // $TEST$ references innerClass + p: »MyClass« + ) -> ( + // $TEST$ references innerClass + r: »MyClass« + ) + } +} diff --git a/tests/resources/scoping/named types/to enum variant in global enum/main.sdstest b/tests/resources/scoping/named types/to enum variant in global enum/main.sdstest new file mode 100644 index 000000000..bd724ecd4 --- /dev/null +++ b/tests/resources/scoping/named types/to enum variant in global enum/main.sdstest @@ -0,0 +1,41 @@ +package test.scoping.namedTypes.toEnumVariantInGlobalEnum + +enum BeforeEnum { + // $TEST$ target before + »BeforeVariant« +} + +class BeforeVariant + +segment mySegment( + // $TEST$ references before + p1: BeforeEnum.»BeforeVariant«, + + // $TEST$ references after + p2: AfterEnum.»AfterVariant«, + + // $TEST$ unresolved + p3: AfterEnum.»BeforeVariant«, + + // $TEST$ unresolved + p4: BeforeEnum.»AfterVariant«, + + // $TEST$ unresolved + p5: BeforeEnum.»Unresolved«, + + // $TEST$ unresolved + p6: AfterEnum.»Unresolved«, + + // $TEST$ unresolved + p7: Unresolved.»BeforeVariant«, + + // $TEST$ unresolved + p8: Unresolved.»AfterVariant«, +) {} + +class AfterVariant + +enum AfterEnum { + // $TEST$ target after + »AfterVariant« +} diff --git a/tests/resources/scoping/named types/to enum variant in nested enum/main.sdstest b/tests/resources/scoping/named types/to enum variant in nested enum/main.sdstest new file mode 100644 index 000000000..41626f98a --- /dev/null +++ b/tests/resources/scoping/named types/to enum variant in nested enum/main.sdstest @@ -0,0 +1,49 @@ +package test.scoping.namedTypes.toEnumVariantInNestedEnum + +class BeforeClass { + enum BeforeEnum { + // $TEST$ target before + »BeforeVariant« + } +} + +enum BeforeEnum { + BeforeVariant +} + +segment mySegment( + // $TEST$ references before + p1: BeforeClass.BeforeEnum.»BeforeVariant«, + + // $TEST$ references after + p2: AfterClass.AfterEnum.»AfterVariant«, + + // $TEST$ unresolved + p3: AfterClass.AfterEnum.»BeforeVariant«, + + // $TEST$ unresolved + p4: BeforeClass.BeforeEnum.»AfterVariant«, + + // $TEST$ unresolved + p5: BeforeClass.BeforeEnum.»Unresolved«, + + // $TEST$ unresolved + p6: AfterClass.AfterEnum.»Unresolved«, + + // $TEST$ unresolved + p7: BeforeClass.Unresolved.»BeforeVariant«, + + // $TEST$ unresolved + p8: AfterClass.Unresolved.»AfterVariant«, +) {} + +enum AfterEnum { + AfterVariant +} + +class AfterClass { + enum AfterEnum { + // $TEST$ target after + »AfterVariant« + } +} diff --git a/tests/resources/scoping/named types/to global class/main.sdstest b/tests/resources/scoping/named types/to global class/main.sdstest new file mode 100644 index 000000000..e1461b1a5 --- /dev/null +++ b/tests/resources/scoping/named types/to global class/main.sdstest @@ -0,0 +1,18 @@ +package test.scoping.namedTypes.toGlobalClass + +// $TEST$ target before +class »BeforeClass« + +segment mySegment( + // $TEST$ references before + p1: »BeforeClass«, + + // $TEST$ references after + p2: »AfterClass«, + + // $TEST$ unresolved + p3: »Unresolved«, +) {} + +// $TEST$ target after +class »AfterClass« diff --git a/tests/resources/scoping/named types/to global enum/main.sdstest b/tests/resources/scoping/named types/to global enum/main.sdstest new file mode 100644 index 000000000..894c55e78 --- /dev/null +++ b/tests/resources/scoping/named types/to global enum/main.sdstest @@ -0,0 +1,18 @@ +package test.scoping.namedTypes.toGlobalEnum + +// $TEST$ target before +enum »BeforeEnum« + +segment mySegment( + // $TEST$ references before + p1: »BeforeEnum«, + + // $TEST$ references after + p2: »AfterEnum«, + + // $TEST$ unresolved + p3: »Unresolved«, +) {} + +// $TEST$ target after +enum »AfterEnum« diff --git a/tests/resources/scoping/named types/to nested class/main.sdstest b/tests/resources/scoping/named types/to nested class/main.sdstest new file mode 100644 index 000000000..46cbe7bc2 --- /dev/null +++ b/tests/resources/scoping/named types/to nested class/main.sdstest @@ -0,0 +1,32 @@ +package test.scoping.namedTypes.toNestedClass + +class BeforeOuterClass { + // $TEST$ target before + class »BeforeInnerClass« +} + +class BeforeInnerClass + +segment mySegment( + // $TEST$ references before + p1: BeforeOuterClass.»BeforeInnerClass«, + + // $TEST$ references after + p2: AfterOuterClass.»AfterInnerClass«, + + // $TEST$ unresolved + p3: BeforeOuterClass.»AfterInnerClass«, + + // $TEST$ unresolved + p4: AfterOuterClass.»BeforeInnerClass«, + + // $TEST$ unresolved + p5: BeforeOuterClass.»Unresolved«, +) {} + +class AfterInnerClass + +class AfterOuterClass { + // $TEST$ target after + class »AfterInnerClass« +} diff --git a/tests/resources/scoping/named types/to nested enum/main.sdstest b/tests/resources/scoping/named types/to nested enum/main.sdstest new file mode 100644 index 000000000..d17e86318 --- /dev/null +++ b/tests/resources/scoping/named types/to nested enum/main.sdstest @@ -0,0 +1,32 @@ +package test.scoping.namedTypes.toNestedEnum + +class BeforeClass { + // $TEST$ target before + enum »BeforeEnum« +} + +enum BeforeEnum + +segment mySegment( + // $TEST$ references before + p1: BeforeClass.»BeforeEnum«, + + // $TEST$ references after + p2: AfterClass.»AfterEnum«, + + // $TEST$ unresolved + p3: BeforeClass.»AfterEnum«, + + // $TEST$ unresolved + p4: AfterClass.»BeforeEnum«, + + // $TEST$ unresolved + p5: BeforeClass.»Unresolved«, +) {} + +enum AfterEnum + +class AfterClass { + // $TEST$ target after + enum »AfterEnum« +} diff --git a/tests/resources/scoping/named types/to something other than named type declaration/main.sdstest b/tests/resources/scoping/named types/to something other than named type declaration/main.sdstest new file mode 100644 index 000000000..d1bc3a5d5 --- /dev/null +++ b/tests/resources/scoping/named types/to something other than named type declaration/main.sdstest @@ -0,0 +1,6 @@ +package test.scoping.namedTypes.toSomethingOtherThanNamedTypeDeclaration + +// $TEST$ unresolved +segment mySegment(p: »notANamedTypeDeclaration«) {} + +fun notANamedTypeDeclaration() From df689c459e7e836fcc10ea06ebfc20a1b2c0ddda Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Tue, 19 Sep 2023 17:09:14 +0200 Subject: [PATCH 06/11] feat: scoping for named types as receiver of member type --- .../scoping/safe-ds-scope-provider.ts | 63 +++++++++++++++++-- 1 file changed, 58 insertions(+), 5 deletions(-) diff --git a/src/language/scoping/safe-ds-scope-provider.ts b/src/language/scoping/safe-ds-scope-provider.ts index 467c8d0a2..8c945f513 100644 --- a/src/language/scoping/safe-ds-scope-provider.ts +++ b/src/language/scoping/safe-ds-scope-provider.ts @@ -1,18 +1,71 @@ import { DefaultScopeProvider, EMPTY_SCOPE, getContainerOfType, ReferenceInfo, Scope } from 'langium'; -import { isSdsSegment, isSdsYield } from '../generated/ast.js'; +import { + isSdsClass, + isSdsEnum, + isSdsMemberType, + isSdsNamedType, isSdsNamedTypeDeclaration, + isSdsSegment, + isSdsYield, + SdsMemberType, + SdsNamedTypeDeclaration, + SdsType, + SdsYield, +} from '../generated/ast.js'; import { resultsOrEmpty } from '../helpers/astShortcuts.js'; export class SafeDsScopeProvider extends DefaultScopeProvider { override getScope(context: ReferenceInfo): Scope { - if (isSdsYield(context.container) && context.property === 'result') { - return this.getScopeForYieldResult(context); + if (isSdsNamedType(context.container) && context.property === 'declaration') { + const node = context.container; + + if (isSdsMemberType(node.$container) && node.$containerProperty === 'member') { + return this.getScopeForMemberTypeMember(node.$container); + } else { + return super.getScope(context); + } + } else if (isSdsYield(context.container) && context.property === 'result') { + return this.getScopeForYieldResult(context.container); } else { return super.getScope(context); } } - getScopeForYieldResult(context: ReferenceInfo): Scope { - const containingSegment = getContainerOfType(context.container, isSdsSegment); + private getScopeForMemberTypeMember(node: SdsMemberType): Scope { + const declaration = this.getUniqueReferencedDeclarationForType(node.receiver); + if (!declaration) { + return EMPTY_SCOPE; + } + + if (isSdsClass(declaration)) { + const members = declaration.body?.members ?? []; + return this.createScopeForNodes(members.filter(isSdsNamedTypeDeclaration)); + } else if (isSdsEnum(declaration)) { + const variants = declaration.body?.variants ?? []; + return this.createScopeForNodes(variants); + } else { + return EMPTY_SCOPE; + } + } + + /** + * Returns the unique declaration that is referenced by this type. If the type references none or multiple + * declarations, undefined is returned. + * + * @param type The type to get the referenced declaration for. + * @returns The referenced declaration or undefined. + */ + private getUniqueReferencedDeclarationForType(type: SdsType): SdsNamedTypeDeclaration | undefined { + if (isSdsNamedType(type)) { + return type.declaration.ref; + } else if (isSdsMemberType(type)) { + return type.member.declaration.ref; + } else { + return undefined; + } + } + + private getScopeForYieldResult(node: SdsYield): Scope { + const containingSegment = getContainerOfType(node, isSdsSegment); if (!containingSegment) { return EMPTY_SCOPE; } From 53e2de1a9eca0ec05a0415d4fccb4bfd907864bc Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Tue, 19 Sep 2023 17:30:47 +0200 Subject: [PATCH 07/11] test: additional tests --- .../main.sdstest | 74 +++++++++++++++---- .../main.sdstest | 20 ++++- .../main.sdstest | 28 ++++++- .../in global class/main.sdstest | 16 +++- .../in global function/main.sdstest | 14 +++- .../to type parameter/in method/main.sdstest | 30 +++++++- .../in nested class/main.sdstest | 28 ++++++- 7 files changed, 183 insertions(+), 27 deletions(-) diff --git a/tests/resources/scoping/named types/to containing named type declaration/main.sdstest b/tests/resources/scoping/named types/to containing named type declaration/main.sdstest index c995fc703..39d7d37a7 100644 --- a/tests/resources/scoping/named types/to containing named type declaration/main.sdstest +++ b/tests/resources/scoping/named types/to containing named type declaration/main.sdstest @@ -1,28 +1,43 @@ package test.scoping.namedTypes.toContainingNamedTypeDeclaration // $TEST$ target outerClass -class »MyClass«( +class »MyClass«( // $TEST$ references outerClass p: »MyClass« -) { +) where { // $TEST$ references outerClass - attr a: »MyClass« + T sub »MyClass« +} { + // $TEST$ references outerClass + attr a1: »MyClass« // $TEST$ unresolved - attr b: »MyEnum« + attr a2: »MyEnum« - fun f( + fun f( // $TEST$ references outerClass - p: »MyClass« + p1: »MyClass«, + + // $TEST$ unresolved + p2: »MyEnum« ) -> ( // $TEST$ references outerClass - r: »MyClass« - ) + r1: »MyClass«, + + // $TEST$ unresolved + r2: »MyEnum« + ) where { + // $TEST$ references outerClass + T sub »MyClass«, + + // $TEST$ unresolved + T sub »MyEnum«, + } // $TEST$ target enum enum »MyEnum« { // $TEST$ target variant - »MyEnumVariant«( + »MyEnumVariant«( // $TEST$ references outerClass p1: »MyClass«, @@ -31,23 +46,50 @@ class »MyClass«( // $TEST$ references variant p3: »MyEnumVariant«, - ) + ) where { + // $TEST$ references outerClass + T sub »MyClass«, + + // $TEST$ references enum + T sub »MyEnum«, + + // $TEST$ references variant + T sub »MyEnumVariant«, + } } // $TEST$ target innerClass class »MyClass«( // $TEST$ references innerClass - p: »MyClass« + p1: »MyClass«, + + // $TEST$ unresolved + p2: »MyEnum«, ) { // $TEST$ references innerClass - attr a: »MyClass« + attr a1: »MyClass« + + // $TEST$ unresolved + attr a2: »MyEnum« - fun f( + fun f( // $TEST$ references innerClass - p: »MyClass« + p1: »MyClass«, + + // $TEST$ unresolved + p2: »MyEnum«, ) -> ( // $TEST$ references innerClass - r: »MyClass« - ) + r1: »MyClass«, + + // $TEST$ unresolved + r2: »MyEnum«, + ) where { + // $TEST$ references innerClass + T sub »MyClass«, + + // $TEST$ unresolved + T sub »MyEnum«, + } } } diff --git a/tests/resources/scoping/named types/to type parameter/in enum variant in global enum/main.sdstest b/tests/resources/scoping/named types/to type parameter/in enum variant in global enum/main.sdstest index ecf16c635..55447373e 100644 --- a/tests/resources/scoping/named types/to type parameter/in enum variant in global enum/main.sdstest +++ b/tests/resources/scoping/named types/to type parameter/in enum variant in global enum/main.sdstest @@ -24,7 +24,25 @@ enum MyEnum { // $TEST$ unresolved f: »Unresolved« - ) + ) where { + // $TEST$ references own + Own sub »Own«, + + // $TEST$ unresolved + Own sub »BeforeEnumVariant«, + + // $TEST$ unresolved + Own sub »AfterEnumVariant«, + + // $TEST$ unresolved + Own sub »BeforeEnum«, + + // $TEST$ unresolved + Own sub »AfterEnum«, + + // $TEST$ unresolved + Own sub »Unresolved«, + } MyEnumVariant3 } diff --git a/tests/resources/scoping/named types/to type parameter/in enum variant in nested enum/main.sdstest b/tests/resources/scoping/named types/to type parameter/in enum variant in nested enum/main.sdstest index 9cf59b37d..88e171b23 100644 --- a/tests/resources/scoping/named types/to type parameter/in enum variant in nested enum/main.sdstest +++ b/tests/resources/scoping/named types/to type parameter/in enum variant in nested enum/main.sdstest @@ -32,8 +32,32 @@ class MyClass<»Container«, Overridden> { g: »AfterEnum«, // $TEST$ unresolved - h: »Unresolved« - ) + h: »Unresolved«, + ) where { + // $TEST$ references own + Own sub »Own«, + + // $TEST$ references overridden + Own sub »Overridden«, + + // $TEST$ references container + Own sub »Container«, + + // $TEST$ unresolved + Own sub »BeforeEnumVariant«, + + // $TEST$ unresolved + Own sub »AfterEnumVariant«, + + // $TEST$ unresolved + Own sub »BeforeEnum«, + + // $TEST$ unresolved + Own sub »AfterEnum«, + + // $TEST$ unresolved + Own sub »Unresolved«, + } MyEnumVariant3 } diff --git a/tests/resources/scoping/named types/to type parameter/in global class/main.sdstest b/tests/resources/scoping/named types/to type parameter/in global class/main.sdstest index dc5bc01c6..4119c17ed 100644 --- a/tests/resources/scoping/named types/to type parameter/in global class/main.sdstest +++ b/tests/resources/scoping/named types/to type parameter/in global class/main.sdstest @@ -14,8 +14,20 @@ class MyClass<»Own«>( c: »After«, // $TEST$ unresolved - d: »Unresolved« -) { + d: »Unresolved«, +) where { + // $TEST$ references own + Own sub »Own«, + + // $TEST$ unresolved + Own sub »Before«, + + // $TEST$ unresolved + Own sub »After«, + + // $TEST$ unresolved + Own sub »Unresolved«, +} { // $TEST$ references own attr z: »Own« diff --git a/tests/resources/scoping/named types/to type parameter/in global function/main.sdstest b/tests/resources/scoping/named types/to type parameter/in global function/main.sdstest index 282f31bb2..0f2d62171 100644 --- a/tests/resources/scoping/named types/to type parameter/in global function/main.sdstest +++ b/tests/resources/scoping/named types/to type parameter/in global function/main.sdstest @@ -27,6 +27,18 @@ fun myFunction2<»Own«>( // $TEST$ unresolved w: »Unresolved« -) +) where { + // $TEST$ references own + Own sub »Own«, + + // $TEST$ unresolved + Own sub »Before«, + + // $TEST$ unresolved + Own sub »After«, + + // $TEST$ unresolved + Own sub »Unresolved« +} fun myFunction3() diff --git a/tests/resources/scoping/named types/to type parameter/in method/main.sdstest b/tests/resources/scoping/named types/to type parameter/in method/main.sdstest index c1a75ba21..66faeaa03 100644 --- a/tests/resources/scoping/named types/to type parameter/in method/main.sdstest +++ b/tests/resources/scoping/named types/to type parameter/in method/main.sdstest @@ -31,7 +31,7 @@ class MyClass1<»Container«, Overridden> { h: »AfterGlobal«, // $TEST$ unresolved - i: »Unresolved« + i: »Unresolved«, ) -> ( // $TEST$ references own z: »Own«, @@ -55,8 +55,32 @@ class MyClass1<»Container«, Overridden> { t: »AfterGlobal«, // $TEST$ unresolved - s: »Unresolved« - ) + s: »Unresolved«, + ) where { + // $TEST$ references own + Own sub »Own«, + + // $TEST$ references overridden + Own sub »Overridden«, + + // $TEST$ references container + Own sub »Container«, + + // $TEST$ unresolved + Own sub »BeforeMember«, + + // $TEST$ unresolved + Own sub »AfterMember«, + + // $TEST$ unresolved + Own sub »BeforeGlobal«, + + // $TEST$ unresolved + Own sub »AfterGlobal«, + + // $TEST$ unresolved + Own sub »Unresolved«, + } fun myFunction5() } diff --git a/tests/resources/scoping/named types/to type parameter/in nested class/main.sdstest b/tests/resources/scoping/named types/to type parameter/in nested class/main.sdstest index f029e5165..79ad0240a 100644 --- a/tests/resources/scoping/named types/to type parameter/in nested class/main.sdstest +++ b/tests/resources/scoping/named types/to type parameter/in nested class/main.sdstest @@ -31,8 +31,32 @@ class MyClass1<»Container«, Overridden> { g: »AfterGlobal«, // $TEST$ unresolved - h: »Unresolved« - ) { + h: »Unresolved«, + ) where { + // $TEST$ references own + Own sub »Own«, + + // $TEST$ references overridden + Own sub »Overridden«, + + // $TEST$ references container + Own sub »Container«, + + // $TEST$ unresolved + Own sub »BeforeMember«, + + // $TEST$ unresolved + Own sub »AfterMember«, + + // $TEST$ unresolved + Own sub »BeforeGlobal«, + + // $TEST$ unresolved + Own sub »AfterGlobal«, + + // $TEST$ unresolved + Own sub »Unresolved«, + } { // $TEST$ references own attr z: »Own« From 0165d1fda1c43a33f594f9f111b95555575514d6 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Tue, 19 Sep 2023 17:36:12 +0200 Subject: [PATCH 08/11] feat: get remaining tests working --- .../scoping/safe-ds-scope-computation.ts | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/language/scoping/safe-ds-scope-computation.ts b/src/language/scoping/safe-ds-scope-computation.ts index d1131b020..afe386589 100644 --- a/src/language/scoping/safe-ds-scope-computation.ts +++ b/src/language/scoping/safe-ds-scope-computation.ts @@ -7,23 +7,55 @@ import { PrecomputedScopes, } from 'langium'; import { - isSdsClass, + isSdsClass, isSdsDeclaration, isSdsEnum, isSdsEnumVariant, - isSdsFunction, + isSdsFunction, isSdsModule, isSdsTypeParameter, isSdsTypeParameterList, + SdsClass, + SdsEnum, SdsTypeParameter, } from '../generated/ast.js'; export class SafeDsScopeComputation extends DefaultScopeComputation { override processNode(node: AstNode, document: LangiumDocument, scopes: PrecomputedScopes): void { - if (isSdsTypeParameter(node)) { + if (isSdsClass(node)) { + this.processSdsClass(node, document, scopes); + } else if (isSdsEnum(node)) { + this.processSdsEnum(node, document, scopes); + } else if (isSdsTypeParameter(node)) { this.processSdsTypeParameter(node, document, scopes); } else { super.processNode(node, document, scopes); } } + private processSdsClass(node: SdsClass, document: LangiumDocument, scopes: PrecomputedScopes): void { + const name = this.nameProvider.getName(node); + const description = this.descriptions.createDescription(node, name, document); + + this.addToScopesIfKeyIsDefined(scopes, node.parameterList, description); + this.addToScopesIfKeyIsDefined(scopes, node.constraintList, description); + this.addToScopesIfKeyIsDefined(scopes, node.body, description); + + const containingDeclaration = getContainerOfType(node.$container, isSdsDeclaration); + if (isSdsModule(containingDeclaration)) { + this.addToScopesIfKeyIsDefined(scopes, containingDeclaration, description) + } + } + + private processSdsEnum(node: SdsEnum, document: LangiumDocument, scopes: PrecomputedScopes): void { + const name = this.nameProvider.getName(node); + const description = this.descriptions.createDescription(node, name, document); + + this.addToScopesIfKeyIsDefined(scopes, node.body, description); + + const containingDeclaration = getContainerOfType(node.$container, isSdsDeclaration); + if (isSdsModule(containingDeclaration)) { + this.addToScopesIfKeyIsDefined(scopes, containingDeclaration, description) + } + } + private processSdsTypeParameter( node: SdsTypeParameter, document: LangiumDocument, From 52c0321d32d74699e350c5b76d21d6589e3e1ce6 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Tue, 19 Sep 2023 17:45:32 +0200 Subject: [PATCH 09/11] fix: failing tests --- src/language/scoping/safe-ds-scope-computation.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/language/scoping/safe-ds-scope-computation.ts b/src/language/scoping/safe-ds-scope-computation.ts index afe386589..a2b5b2489 100644 --- a/src/language/scoping/safe-ds-scope-computation.ts +++ b/src/language/scoping/safe-ds-scope-computation.ts @@ -32,6 +32,10 @@ export class SafeDsScopeComputation extends DefaultScopeComputation { private processSdsClass(node: SdsClass, document: LangiumDocument, scopes: PrecomputedScopes): void { const name = this.nameProvider.getName(node); + if (!name) { + return; + } + const description = this.descriptions.createDescription(node, name, document); this.addToScopesIfKeyIsDefined(scopes, node.parameterList, description); @@ -46,6 +50,10 @@ export class SafeDsScopeComputation extends DefaultScopeComputation { private processSdsEnum(node: SdsEnum, document: LangiumDocument, scopes: PrecomputedScopes): void { const name = this.nameProvider.getName(node); + if (!name) { + return; + } + const description = this.descriptions.createDescription(node, name, document); this.addToScopesIfKeyIsDefined(scopes, node.body, description); @@ -67,6 +75,10 @@ export class SafeDsScopeComputation extends DefaultScopeComputation { } const name = this.nameProvider.getName(node); + if (!name) { + return; + } + const description = this.descriptions.createDescription(node, name, document); if (isSdsClass(containingDeclaration)) { From 82e97bc72de16f984cca725e42d7ee6cf02a3219 Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Tue, 19 Sep 2023 15:48:00 +0000 Subject: [PATCH 10/11] style: apply automated linter fixes --- src/language/scoping/safe-ds-scope-computation.ts | 11 +++++++---- src/language/scoping/safe-ds-scope-provider.ts | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/language/scoping/safe-ds-scope-computation.ts b/src/language/scoping/safe-ds-scope-computation.ts index a2b5b2489..afe4c0bfd 100644 --- a/src/language/scoping/safe-ds-scope-computation.ts +++ b/src/language/scoping/safe-ds-scope-computation.ts @@ -7,9 +7,12 @@ import { PrecomputedScopes, } from 'langium'; import { - isSdsClass, isSdsDeclaration, isSdsEnum, + isSdsClass, + isSdsDeclaration, + isSdsEnum, isSdsEnumVariant, - isSdsFunction, isSdsModule, + isSdsFunction, + isSdsModule, isSdsTypeParameter, isSdsTypeParameterList, SdsClass, @@ -44,7 +47,7 @@ export class SafeDsScopeComputation extends DefaultScopeComputation { const containingDeclaration = getContainerOfType(node.$container, isSdsDeclaration); if (isSdsModule(containingDeclaration)) { - this.addToScopesIfKeyIsDefined(scopes, containingDeclaration, description) + this.addToScopesIfKeyIsDefined(scopes, containingDeclaration, description); } } @@ -60,7 +63,7 @@ export class SafeDsScopeComputation extends DefaultScopeComputation { const containingDeclaration = getContainerOfType(node.$container, isSdsDeclaration); if (isSdsModule(containingDeclaration)) { - this.addToScopesIfKeyIsDefined(scopes, containingDeclaration, description) + this.addToScopesIfKeyIsDefined(scopes, containingDeclaration, description); } } diff --git a/src/language/scoping/safe-ds-scope-provider.ts b/src/language/scoping/safe-ds-scope-provider.ts index 8c945f513..96a99c6ea 100644 --- a/src/language/scoping/safe-ds-scope-provider.ts +++ b/src/language/scoping/safe-ds-scope-provider.ts @@ -3,7 +3,8 @@ import { isSdsClass, isSdsEnum, isSdsMemberType, - isSdsNamedType, isSdsNamedTypeDeclaration, + isSdsNamedType, + isSdsNamedTypeDeclaration, isSdsSegment, isSdsYield, SdsMemberType, From 0533dde26d0d944872b1a0d9f235d1a22c2432a0 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Tue, 19 Sep 2023 17:51:10 +0200 Subject: [PATCH 11/11] test: ignore two lines for coverage --- src/language/scoping/safe-ds-scope-computation.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/language/scoping/safe-ds-scope-computation.ts b/src/language/scoping/safe-ds-scope-computation.ts index afe4c0bfd..447fcd205 100644 --- a/src/language/scoping/safe-ds-scope-computation.ts +++ b/src/language/scoping/safe-ds-scope-computation.ts @@ -74,11 +74,13 @@ export class SafeDsScopeComputation extends DefaultScopeComputation { ): void { const containingDeclaration = getContainerOfType(node, isSdsTypeParameterList)?.$container; if (!containingDeclaration) { + /* c8 ignore next 2 */ return; } const name = this.nameProvider.getName(node); if (!name) { + /* c8 ignore next 2 */ return; }