diff --git a/src/language/scoping/safe-ds-scope-computation.ts b/src/language/scoping/safe-ds-scope-computation.ts index d1131b020..447fcd205 100644 --- a/src/language/scoping/safe-ds-scope-computation.ts +++ b/src/language/scoping/safe-ds-scope-computation.ts @@ -8,22 +8,65 @@ import { } from 'langium'; import { isSdsClass, + isSdsDeclaration, + isSdsEnum, isSdsEnumVariant, 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); + if (!name) { + return; + } + + 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); + if (!name) { + return; + } + + 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, @@ -31,10 +74,16 @@ 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; + } + const description = this.descriptions.createDescription(node, name, document); if (isSdsClass(containingDeclaration)) { diff --git a/src/language/scoping/safe-ds-scope-provider.ts b/src/language/scoping/safe-ds-scope-provider.ts index 467c8d0a2..96a99c6ea 100644 --- a/src/language/scoping/safe-ds-scope-provider.ts +++ b/src/language/scoping/safe-ds-scope-provider.ts @@ -1,18 +1,72 @@ 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; } 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 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..39d7d37a7 --- /dev/null +++ b/tests/resources/scoping/named types/to containing named type declaration/main.sdstest @@ -0,0 +1,95 @@ +package test.scoping.namedTypes.toContainingNamedTypeDeclaration + +// $TEST$ target outerClass +class »MyClass«( + // $TEST$ references outerClass + p: »MyClass« +) where { + // $TEST$ references outerClass + T sub »MyClass« +} { + // $TEST$ references outerClass + attr a1: »MyClass« + + // $TEST$ unresolved + attr a2: »MyEnum« + + fun f( + // $TEST$ references outerClass + p1: »MyClass«, + + // $TEST$ unresolved + p2: »MyEnum« + ) -> ( + // $TEST$ references outerClass + 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«( + // $TEST$ references outerClass + p1: »MyClass«, + + // $TEST$ references enum + p2: »MyEnum«, + + // $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 + p1: »MyClass«, + + // $TEST$ unresolved + p2: »MyEnum«, + ) { + // $TEST$ references innerClass + attr a1: »MyClass« + + // $TEST$ unresolved + attr a2: »MyEnum« + + fun f( + // $TEST$ references innerClass + p1: »MyClass«, + + // $TEST$ unresolved + p2: »MyEnum«, + ) -> ( + // $TEST$ references innerClass + 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 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() 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..55447373e --- /dev/null +++ b/tests/resources/scoping/named types/to type parameter/in enum variant in global enum/main.sdstest @@ -0,0 +1,50 @@ +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« + ) 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 +} + +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..88e171b23 --- /dev/null +++ b/tests/resources/scoping/named types/to type parameter/in enum variant in nested enum/main.sdstest @@ -0,0 +1,66 @@ +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«, + ) 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 + } +} + +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..4119c17ed --- /dev/null +++ b/tests/resources/scoping/named types/to type parameter/in global class/main.sdstest @@ -0,0 +1,44 @@ +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«, +) 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« + + // $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..0f2d62171 --- /dev/null +++ b/tests/resources/scoping/named types/to type parameter/in global function/main.sdstest @@ -0,0 +1,44 @@ +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« +) 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 new file mode 100644 index 000000000..66faeaa03 --- /dev/null +++ b/tests/resources/scoping/named types/to type parameter/in method/main.sdstest @@ -0,0 +1,88 @@ +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«, + ) 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() +} + +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..79ad0240a --- /dev/null +++ b/tests/resources/scoping/named types/to type parameter/in nested class/main.sdstest @@ -0,0 +1,88 @@ +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«, + ) 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« + + // $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() 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 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