From a510f2b77c9820d572e7d1fee24bdb028d9d13fd Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Mon, 18 Sep 2023 17:19:49 +0200 Subject: [PATCH] feat: scoping of annotation calls, type parameter constraints & yields (#561) Closes partially #540 ### Summary of Changes * Implement scoping for * annotation calls (_annotation_) * type parameter constraints (_left operand_) * yields (_result_) --- src/language/formatting/safe-ds-formatter.ts | 2 +- src/language/grammar/safe-ds.langium | 2 +- src/language/helpers/astShortcuts.ts | 6 +- src/language/safe-ds-module.ts | 10 ++- .../scoping/safe-ds-scope-computation.ts | 66 +++++++++++++++++++ .../scoping/safe-ds-scope-provider.ts | 22 +++++++ .../safeds/lang/schemaEffects.sdsstub | 43 ------------ .../on annotation/main.sdstest | 15 +++++ .../on attribute/main.sdstest | 17 +++++ .../annotation calls/on class/main.sdstest | 15 +++++ .../on enum variant/main.sdstest | 17 +++++ .../annotation calls/on enum/main.sdstest | 15 +++++ .../annotation calls/on function/main.sdstest | 15 +++++ .../annotation calls/on module/main.sdstest | 9 +++ .../on parameter/main.sdstest | 17 +++++ .../annotation calls/on pipeline/main.sdstest | 15 +++++ .../annotation calls/on result/main.sdstest | 17 +++++ .../annotation calls/on segment/main.sdstest | 15 +++++ .../on type parameter/main.sdstest | 17 +++++ .../annotation calls/test1/main.sdstest | 10 --- .../annotation calls/test1/resource1.sdstest | 0 .../in annotation/main.sdstest | 16 +++++ .../main.sdstest | 32 +++++++++ .../main.sdstest | 42 ++++++++++++ .../in global class/main.sdstest | 20 ++++++ .../in global function/main.sdstest | 20 ++++++ .../in method/main.sdstest | 41 ++++++++++++ .../in nested class/main.sdstest | 41 ++++++++++++ .../scoping/yields/in pipeline/main.sdstest | 16 +++++ .../scoping/yields/in segment/main.sdstest | 22 +++++++ 30 files changed, 537 insertions(+), 58 deletions(-) create mode 100644 src/language/scoping/safe-ds-scope-computation.ts create mode 100644 src/language/scoping/safe-ds-scope-provider.ts delete mode 100644 src/resources/builtins/safeds/lang/schemaEffects.sdsstub create mode 100644 tests/resources/scoping/annotation calls/on annotation/main.sdstest create mode 100644 tests/resources/scoping/annotation calls/on attribute/main.sdstest create mode 100644 tests/resources/scoping/annotation calls/on class/main.sdstest create mode 100644 tests/resources/scoping/annotation calls/on enum variant/main.sdstest create mode 100644 tests/resources/scoping/annotation calls/on enum/main.sdstest create mode 100644 tests/resources/scoping/annotation calls/on function/main.sdstest create mode 100644 tests/resources/scoping/annotation calls/on module/main.sdstest create mode 100644 tests/resources/scoping/annotation calls/on parameter/main.sdstest create mode 100644 tests/resources/scoping/annotation calls/on pipeline/main.sdstest create mode 100644 tests/resources/scoping/annotation calls/on result/main.sdstest create mode 100644 tests/resources/scoping/annotation calls/on segment/main.sdstest create mode 100644 tests/resources/scoping/annotation calls/on type parameter/main.sdstest delete mode 100644 tests/resources/scoping/annotation calls/test1/main.sdstest delete mode 100644 tests/resources/scoping/annotation calls/test1/resource1.sdstest create mode 100644 tests/resources/scoping/type parameter constraints/in annotation/main.sdstest create mode 100644 tests/resources/scoping/type parameter constraints/in enum variant in global enum/main.sdstest create mode 100644 tests/resources/scoping/type parameter constraints/in enum variant in nested enum/main.sdstest create mode 100644 tests/resources/scoping/type parameter constraints/in global class/main.sdstest create mode 100644 tests/resources/scoping/type parameter constraints/in global function/main.sdstest create mode 100644 tests/resources/scoping/type parameter constraints/in method/main.sdstest create mode 100644 tests/resources/scoping/type parameter constraints/in nested class/main.sdstest create mode 100644 tests/resources/scoping/yields/in pipeline/main.sdstest create mode 100644 tests/resources/scoping/yields/in segment/main.sdstest diff --git a/src/language/formatting/safe-ds-formatter.ts b/src/language/formatting/safe-ds-formatter.ts index 62c2935ad..424c91ef7 100644 --- a/src/language/formatting/safe-ds-formatter.ts +++ b/src/language/formatting/safe-ds-formatter.ts @@ -20,7 +20,7 @@ const newLinesWithIndent = function (count: number, options?: FormattingActionOp }; }; -export class SafeDSFormatter extends AbstractFormatter { +export class SafeDsFormatter extends AbstractFormatter { protected override format(node: AstNode): void { // ----------------------------------------------------------------------------- // Module diff --git a/src/language/grammar/safe-ds.langium b/src/language/grammar/safe-ds.langium index 87263ac20..3917f0bd7 100644 --- a/src/language/grammar/safe-ds.langium +++ b/src/language/grammar/safe-ds.langium @@ -373,7 +373,7 @@ SdsTypeParameterConstraintOperator returns string: // ----------------------------------------------------------------------------- interface SdsCallable extends SdsObject { - parameterList: SdsParameterList + parameterList?: SdsParameterList } interface SdsParameterList extends SdsObject { diff --git a/src/language/helpers/astShortcuts.ts b/src/language/helpers/astShortcuts.ts index dd5ab4564..3fbbe3bba 100644 --- a/src/language/helpers/astShortcuts.ts +++ b/src/language/helpers/astShortcuts.ts @@ -4,7 +4,7 @@ import { SdsAnnotatedObject, SdsAnnotationCall, SdsLiteral, - SdsLiteralType, + SdsLiteralType, SdsResult, SdsResultList, SdsTypeArgument, SdsTypeArgumentList, } from '../generated/ast.js'; @@ -21,6 +21,10 @@ export const literalsOrEmpty = function (node: SdsLiteralType | undefined): SdsL return node?.literalList?.literals ?? []; }; +export const resultsOrEmpty = function (node: SdsResultList | undefined): SdsResult[] { + return node?.results ?? []; +} + export const typeArgumentsOrEmpty = function (node: SdsTypeArgumentList | undefined): SdsTypeArgument[] { return node?.typeArguments ?? []; }; diff --git a/src/language/safe-ds-module.ts b/src/language/safe-ds-module.ts index b7fb812c1..a61ff8189 100644 --- a/src/language/safe-ds-module.ts +++ b/src/language/safe-ds-module.ts @@ -11,8 +11,10 @@ import { } from 'langium'; import { SafeDsGeneratedModule, SafeDsGeneratedSharedModule } from './generated/module.js'; import { SafeDsValidator, registerValidationChecks } from './validation/safe-ds-validator.js'; -import { SafeDSFormatter } from './formatting/safe-ds-formatter.js'; +import { SafeDsFormatter } from './formatting/safe-ds-formatter.js'; import { SafeDsWorkspaceManager } from './builtins/workspaceManager.js'; +import {SafeDsScopeComputation} from "./scoping/safe-ds-scope-computation.js"; +import {SafeDsScopeProvider} from "./scoping/safe-ds-scope-provider.js"; /** * Declaration of custom services - add your own service classes here. @@ -36,7 +38,11 @@ export type SafeDsServices = LangiumServices & SafeDsAddedServices; */ export const SafeDsModule: Module = { lsp: { - Formatter: () => new SafeDSFormatter(), + Formatter: () => new SafeDsFormatter(), + }, + references: { + ScopeComputation: (services) => new SafeDsScopeComputation(services), + ScopeProvider: (services) => new SafeDsScopeProvider(services), }, validation: { SafeDsValidator: () => new SafeDsValidator(), diff --git a/src/language/scoping/safe-ds-scope-computation.ts b/src/language/scoping/safe-ds-scope-computation.ts new file mode 100644 index 000000000..d1131b020 --- /dev/null +++ b/src/language/scoping/safe-ds-scope-computation.ts @@ -0,0 +1,66 @@ +import { + AstNode, + AstNodeDescription, + DefaultScopeComputation, + getContainerOfType, + LangiumDocument, + PrecomputedScopes, +} from 'langium'; +import { + isSdsClass, + isSdsEnumVariant, + isSdsFunction, + isSdsTypeParameter, + isSdsTypeParameterList, + SdsTypeParameter, +} from '../generated/ast.js'; + +export class SafeDsScopeComputation extends DefaultScopeComputation { + override processNode(node: AstNode, document: LangiumDocument, scopes: PrecomputedScopes): void { + if (isSdsTypeParameter(node)) { + this.processSdsTypeParameter(node, document, scopes); + } else { + super.processNode(node, document, scopes); + } + } + + private processSdsTypeParameter( + node: SdsTypeParameter, + document: LangiumDocument, + scopes: PrecomputedScopes, + ): void { + const containingDeclaration = getContainerOfType(node, isSdsTypeParameterList)?.$container; + if (!containingDeclaration) { + return; + } + + const name = this.nameProvider.getName(node); + const description = this.descriptions.createDescription(node, name, document); + + if (isSdsClass(containingDeclaration)) { + this.addToScopesIfKeyIsDefined(scopes, containingDeclaration.parameterList, description); + this.addToScopesIfKeyIsDefined(scopes, containingDeclaration.constraintList, description); + this.addToScopesIfKeyIsDefined(scopes, containingDeclaration.body, description); + } else if (isSdsEnumVariant(containingDeclaration)) { + this.addToScopesIfKeyIsDefined(scopes, containingDeclaration.parameterList, description); + this.addToScopesIfKeyIsDefined(scopes, containingDeclaration.constraintList, description); + } else if (isSdsFunction(containingDeclaration)) { + this.addToScopesIfKeyIsDefined(scopes, containingDeclaration.parameterList, description); + this.addToScopesIfKeyIsDefined(scopes, containingDeclaration.resultList, description); + this.addToScopesIfKeyIsDefined(scopes, containingDeclaration.constraintList, description); + } + } + + /** + * Adds the key/value pair to the scopes if the key is defined. + * + * @param scopes The scopes to add the key/value pair to. + * @param key The key. + * @param value The value. + */ + addToScopesIfKeyIsDefined(scopes: PrecomputedScopes, key: AstNode | undefined, value: AstNodeDescription): void { + if (key) { + scopes.add(key, value); + } + } +} diff --git a/src/language/scoping/safe-ds-scope-provider.ts b/src/language/scoping/safe-ds-scope-provider.ts new file mode 100644 index 000000000..467c8d0a2 --- /dev/null +++ b/src/language/scoping/safe-ds-scope-provider.ts @@ -0,0 +1,22 @@ +import { DefaultScopeProvider, EMPTY_SCOPE, getContainerOfType, ReferenceInfo, Scope } from 'langium'; +import { isSdsSegment, isSdsYield } 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); + } else { + return super.getScope(context); + } + } + + getScopeForYieldResult(context: ReferenceInfo): Scope { + const containingSegment = getContainerOfType(context.container, isSdsSegment); + if (!containingSegment) { + return EMPTY_SCOPE; + } + + return this.createScopeForNodes(resultsOrEmpty(containingSegment.resultList)); + } +} diff --git a/src/resources/builtins/safeds/lang/schemaEffects.sdsstub b/src/resources/builtins/safeds/lang/schemaEffects.sdsstub deleted file mode 100644 index 9a54b5bd2..000000000 --- a/src/resources/builtins/safeds/lang/schemaEffects.sdsstub +++ /dev/null @@ -1,43 +0,0 @@ -package safeds.lang - -@Description("Reads the initial data schema of a dataset.") -abstract predicate $readSchema ( - datasetPath: String, -) -> ::InitialSchema - -@Description("Checks if the columns with the names 'columnName' exist in the data schema.") -abstract predicate $checkColumn ( - ::CurrentSchema, - vararg columnName: String, -) -> ::SchemaOut - -@Description("Remove all the columns with the names 'columnName' from the data schema.") -abstract predicate $removeColumn ( - ::CurrentSchema, - vararg columnName: String, -) -> ::SchemaOut - -@Description("Remove all the columns other than the ones with names 'columnName' from the data schema.") -abstract predicate $keepColumn ( - ::CurrentSchema, - vararg columnName: String, -) -> ::SchemaOut - -@Description("Rename the column with name 'currentColumnName' to 'newColumnName' in the data schema if the column exists.") -abstract predicate $renameColumn ( - ::CurrentSchema, - currentColumnName: String, - newColumnName: String, -) -> ::SchemaOut - -@Description("Add a column with name 'newColumnName' and datatype 'NewColumnDataType' in the data schema unless there is already one with the same name.") -abstract predicate $addColumn ( - ::CurrentSchema, - newColumnName: String, -) -> ::SchemaOut - -@Description("Change the datatype to 'NewColumnDataType' of a column with name 'ColumnName' in the data schema.") -abstract predicate $changeColumnType ( - ::CurrentSchema, - columnName: String, -) -> ::SchemaOut \ No newline at end of file diff --git a/tests/resources/scoping/annotation calls/on annotation/main.sdstest b/tests/resources/scoping/annotation calls/on annotation/main.sdstest new file mode 100644 index 000000000..d9a19539c --- /dev/null +++ b/tests/resources/scoping/annotation calls/on annotation/main.sdstest @@ -0,0 +1,15 @@ +package test.scoping.annotationCalls.onAnnotation + +// $TEST$ target before +annotation »Before« + +// $TEST$ references before +@»Before« +// $TEST$ references after +@»After« +// $TEST$ unresolved +@»Unresolved« +annotation MyAnnotation + +// $TEST$ target after +annotation »After« diff --git a/tests/resources/scoping/annotation calls/on attribute/main.sdstest b/tests/resources/scoping/annotation calls/on attribute/main.sdstest new file mode 100644 index 000000000..aed38fa55 --- /dev/null +++ b/tests/resources/scoping/annotation calls/on attribute/main.sdstest @@ -0,0 +1,17 @@ +package test.scoping.annotationCalls.onAttribute + +// $TEST$ target before +annotation »Before« + +class MyClass { + // $TEST$ references before + @»Before« + // $TEST$ references after + @»After« + // $TEST$ unresolved + @»Unresolved« + attr myAttribute: Int +} + +// $TEST$ target after +annotation »After« diff --git a/tests/resources/scoping/annotation calls/on class/main.sdstest b/tests/resources/scoping/annotation calls/on class/main.sdstest new file mode 100644 index 000000000..e28243da1 --- /dev/null +++ b/tests/resources/scoping/annotation calls/on class/main.sdstest @@ -0,0 +1,15 @@ +package test.scoping.annotationCalls.onClass + +// $TEST$ target before +annotation »Before« + +// $TEST$ references before +@»Before« +// $TEST$ references after +@»After« +// $TEST$ unresolved +@»Unresolved« +class MyClass + +// $TEST$ target after +annotation »After« diff --git a/tests/resources/scoping/annotation calls/on enum variant/main.sdstest b/tests/resources/scoping/annotation calls/on enum variant/main.sdstest new file mode 100644 index 000000000..98187558e --- /dev/null +++ b/tests/resources/scoping/annotation calls/on enum variant/main.sdstest @@ -0,0 +1,17 @@ +package test.scoping.annotationCalls.onEnumVariant + +// $TEST$ target before +annotation »Before« + +enum MyEnum { + // $TEST$ references before + @»Before« + // $TEST$ references after + @»After« + // $TEST$ unresolved + @»Unresolved« + MyEnumVariant +} + +// $TEST$ target after +annotation »After« diff --git a/tests/resources/scoping/annotation calls/on enum/main.sdstest b/tests/resources/scoping/annotation calls/on enum/main.sdstest new file mode 100644 index 000000000..4441b46e4 --- /dev/null +++ b/tests/resources/scoping/annotation calls/on enum/main.sdstest @@ -0,0 +1,15 @@ +package test.scoping.annotationCalls.onEnum + +// $TEST$ target before +annotation »Before« + +// $TEST$ references before +@»Before« +// $TEST$ references after +@»After« +// $TEST$ unresolved +@»Unresolved« +enum MyEnum + +// $TEST$ target after +annotation »After« diff --git a/tests/resources/scoping/annotation calls/on function/main.sdstest b/tests/resources/scoping/annotation calls/on function/main.sdstest new file mode 100644 index 000000000..025c439d5 --- /dev/null +++ b/tests/resources/scoping/annotation calls/on function/main.sdstest @@ -0,0 +1,15 @@ +package test.scoping.annotationCalls.onFunction + +// $TEST$ target before +annotation »Before« + +// $TEST$ references before +@»Before« +// $TEST$ references after +@»After« +// $TEST$ unresolved +@»Unresolved« +fun myFunction() + +// $TEST$ target after +annotation »After« diff --git a/tests/resources/scoping/annotation calls/on module/main.sdstest b/tests/resources/scoping/annotation calls/on module/main.sdstest new file mode 100644 index 000000000..768322311 --- /dev/null +++ b/tests/resources/scoping/annotation calls/on module/main.sdstest @@ -0,0 +1,9 @@ +// $TEST$ references annotation +@»MyAnnotation« +// $TEST$ unresolved +@»Unresolved« + +package test.scoping.annotationCalls.onModule + +// $TEST$ target annotation +annotation »MyAnnotation« diff --git a/tests/resources/scoping/annotation calls/on parameter/main.sdstest b/tests/resources/scoping/annotation calls/on parameter/main.sdstest new file mode 100644 index 000000000..5990b98c0 --- /dev/null +++ b/tests/resources/scoping/annotation calls/on parameter/main.sdstest @@ -0,0 +1,17 @@ +package test.scoping.annotationCalls.onParameter + +// $TEST$ target before +annotation »Before« + +fun myFunction( + // $TEST$ references before + @»Before« + // $TEST$ references after + @»After« + // $TEST$ unresolved + @»Unresolved« + myParameter: Int +) + +// $TEST$ target after +annotation »After« diff --git a/tests/resources/scoping/annotation calls/on pipeline/main.sdstest b/tests/resources/scoping/annotation calls/on pipeline/main.sdstest new file mode 100644 index 000000000..40f1f5171 --- /dev/null +++ b/tests/resources/scoping/annotation calls/on pipeline/main.sdstest @@ -0,0 +1,15 @@ +package test.scoping.annotationCalls.onPipeline + +// $TEST$ target before +annotation »Before« + +// $TEST$ references before +@»Before« +// $TEST$ references after +@»After« +// $TEST$ unresolved +@»Unresolved« +pipeline myPipeline {} + +// $TEST$ target after +annotation »After« diff --git a/tests/resources/scoping/annotation calls/on result/main.sdstest b/tests/resources/scoping/annotation calls/on result/main.sdstest new file mode 100644 index 000000000..1bd82e4e3 --- /dev/null +++ b/tests/resources/scoping/annotation calls/on result/main.sdstest @@ -0,0 +1,17 @@ +package test.scoping.annotationCalls.onResult + +// $TEST$ target before +annotation »Before« + +fun myFunction() -> ( + // $TEST$ references before + @»Before« + // $TEST$ references after + @»After« + // $TEST$ unresolved + @»Unresolved« + myResult: Int +) + +// $TEST$ target after +annotation »After« diff --git a/tests/resources/scoping/annotation calls/on segment/main.sdstest b/tests/resources/scoping/annotation calls/on segment/main.sdstest new file mode 100644 index 000000000..59d4c99e4 --- /dev/null +++ b/tests/resources/scoping/annotation calls/on segment/main.sdstest @@ -0,0 +1,15 @@ +package test.scoping.annotationCalls.onSegment + +// $TEST$ target before +annotation »Before« + +// $TEST$ references before +@»Before« +// $TEST$ references after +@»After« +// $TEST$ unresolved +@»Unresolved« +segment mySegment() {} + +// $TEST$ target after +annotation »After« diff --git a/tests/resources/scoping/annotation calls/on type parameter/main.sdstest b/tests/resources/scoping/annotation calls/on type parameter/main.sdstest new file mode 100644 index 000000000..5e400106d --- /dev/null +++ b/tests/resources/scoping/annotation calls/on type parameter/main.sdstest @@ -0,0 +1,17 @@ +package test.scoping.annotationCalls.onTypeParameter + +// $TEST$ target before +annotation »Before« + +fun myFunction< + // $TEST$ references before + @»Before« + // $TEST$ references after + @»After« + // $TEST$ unresolved + @»Unresolved« + MyTypeParameter +>() + +// $TEST$ target after +annotation »After« diff --git a/tests/resources/scoping/annotation calls/test1/main.sdstest b/tests/resources/scoping/annotation calls/test1/main.sdstest deleted file mode 100644 index 03ab74e86..000000000 --- a/tests/resources/scoping/annotation calls/test1/main.sdstest +++ /dev/null @@ -1,10 +0,0 @@ -// $TEST$ target class_C -class »C« - -pipeline test { - // $TEST$ references class_C - »C«(); - - // $TEST$ unresolved - »D«; -} diff --git a/tests/resources/scoping/annotation calls/test1/resource1.sdstest b/tests/resources/scoping/annotation calls/test1/resource1.sdstest deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/scoping/type parameter constraints/in annotation/main.sdstest b/tests/resources/scoping/type parameter constraints/in annotation/main.sdstest new file mode 100644 index 000000000..1586f2b2b --- /dev/null +++ b/tests/resources/scoping/type parameter constraints/in annotation/main.sdstest @@ -0,0 +1,16 @@ +package test.scoping.typeParameterConstraints.inAnnotation + +fun myFunction1() + +annotation MyAnnotation where { + // $TEST$ unresolved + »Before« sub Int, + + // $TEST$ unresolved + »After« sub Int, + + // $TEST$ unresolved + »Unresolved« sub Int +} + +fun myFunction2() 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 new file mode 100644 index 000000000..36d541d40 --- /dev/null +++ b/tests/resources/scoping/type parameter constraints/in enum variant in global enum/main.sdstest @@ -0,0 +1,32 @@ +package test.scoping.typeParameterConstraints.inEnumVariantInGlobalEnum + +fun myFunction1() + +enum MyEnum { + MyEnumVariant1 + + // $TEST$ target own + MyEnumVariant2<»Own«> where { + // $TEST$ references own + »Own« sub Int, + + // $TEST$ unresolved + »BeforeEnumVariant« sub Int, + + // $TEST$ unresolved + »AfterEnumVariant« sub Int, + + // $TEST$ unresolved + »BeforeEnum« sub Int, + + // $TEST$ unresolved + »AfterEnum« sub Int, + + // $TEST$ unresolved + »Unresolved« sub Int + } + + MyEnumVariant3 +} + +fun myFunction2() 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 new file mode 100644 index 000000000..51923e792 --- /dev/null +++ b/tests/resources/scoping/type parameter constraints/in enum variant in nested enum/main.sdstest @@ -0,0 +1,42 @@ +package test.scoping.typeParameterConstraints.inEnumVariantInNestedEnum + +fun myFunction1() + +// $TEST$ target container +class MyClass<»Container«, Overridden> { + enum MyEnum { + MyEnumVariant1 + + // $TEST$ target own + // $TEST$ target overridden + MyEnumVariant2<»Own«, »Overridden«> where { + // $TEST$ references own + »Own« sub Int, + + // $TEST$ references overridden + »Overridden« sub Int, + + // $TEST$ references container + »Container« sub Int, + + // $TEST$ unresolved + »BeforeEnumVariant« sub Int, + + // $TEST$ unresolved + »AfterEnumVariant« sub Int, + + // $TEST$ unresolved + »BeforeEnum« sub Int, + + // $TEST$ unresolved + »AfterEnum« sub Int, + + // $TEST$ unresolved + »Unresolved« sub Int + } + + MyEnumVariant3 + } +} + +fun myFunction2() 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 new file mode 100644 index 000000000..640c21158 --- /dev/null +++ b/tests/resources/scoping/type parameter constraints/in global class/main.sdstest @@ -0,0 +1,20 @@ +package test.scoping.typeParameterConstraints.inGlobalClass + +fun myFunction1() + +// $TEST$ target own +class MyClass<»Own«> where { + // $TEST$ references own + »Own« sub Int, + + // $TEST$ unresolved + »Before« sub Int, + + // $TEST$ unresolved + »After« sub Int, + + // $TEST$ unresolved + »Unresolved« sub Int +} + +fun myFunction2() 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 new file mode 100644 index 000000000..803afd004 --- /dev/null +++ b/tests/resources/scoping/type parameter constraints/in global function/main.sdstest @@ -0,0 +1,20 @@ +package test.scoping.typeParameterConstraints.inGlobalFunction + +fun myFunction1() + +// $TEST$ target own +fun myFunction2<»Own«>() where { + // $TEST$ references own + »Own« sub Int, + + // $TEST$ unresolved + »Before« sub Int, + + // $TEST$ unresolved + »After« sub Int, + + // $TEST$ unresolved + »Unresolved« sub Int +} + +fun myFunction3() diff --git a/tests/resources/scoping/type parameter constraints/in method/main.sdstest b/tests/resources/scoping/type parameter constraints/in method/main.sdstest new file mode 100644 index 000000000..0ebd8a9c8 --- /dev/null +++ b/tests/resources/scoping/type parameter constraints/in method/main.sdstest @@ -0,0 +1,41 @@ +package test.scoping.typeParameterConstraints.inMethod + +fun myFunction1() + +// $TEST$ target container +class MyClass1<»Container«, Overridden> { + fun myFunction2() + + // $TEST$ target own + // $TEST$ target overridden + fun myFunction3<»Own«, »Overridden«>() where { + // $TEST$ references own + »Own« sub Int, + + // $TEST$ references overridden + »Overridden« sub Int, + + // $TEST$ references container + »Container« sub Int, + + // $TEST$ unresolved + »BeforeMember« sub Int, + + // $TEST$ unresolved + »AfterMember« sub Int, + + // $TEST$ unresolved + »BeforeGlobal« sub Int, + + // $TEST$ unresolved + »AfterGlobal« sub Int, + + // $TEST$ unresolved + »Unresolved« sub Int + } + + fun myFunction5() +} + + +fun myFunction5() 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 new file mode 100644 index 000000000..0af703364 --- /dev/null +++ b/tests/resources/scoping/type parameter constraints/in nested class/main.sdstest @@ -0,0 +1,41 @@ +package test.scoping.typeParameterConstraints.inNestedClass + +fun myFunction1() + +// $TEST$ target container +class MyClass1<»Container«, Overridden> { + fun myFunction2() + + // $TEST$ target own + // $TEST$ target overridden + class MyClass2<»Own«, »Overridden«> where { + // $TEST$ references own + »Own« sub Int, + + // $TEST$ references overridden + »Overridden« sub Int, + + // $TEST$ references container + »Container« sub Int, + + // $TEST$ unresolved + »BeforeMember« sub Int, + + // $TEST$ unresolved + »AfterMember« sub Int, + + // $TEST$ unresolved + »BeforeGlobal« sub Int, + + // $TEST$ unresolved + »AfterGlobal« sub Int, + + // $TEST$ unresolved + »Unresolved« sub Int + } + + fun myFunction3() +} + + +fun myFunction4() diff --git a/tests/resources/scoping/yields/in pipeline/main.sdstest b/tests/resources/scoping/yields/in pipeline/main.sdstest new file mode 100644 index 000000000..217f68d20 --- /dev/null +++ b/tests/resources/scoping/yields/in pipeline/main.sdstest @@ -0,0 +1,16 @@ +package test.scoping.yields.inPipeline + +segment mySegment1() -> before: Int {} + +pipeline myPipeline { + // $TEST$ unresolved + yield »before« = 1; + + // $TEST$ unresolved + yield »after« = 1; + + // $TEST$ unresolved + yield »unresolved« = 1; +} + +segment mySegment2() -> after: Int {} diff --git a/tests/resources/scoping/yields/in segment/main.sdstest b/tests/resources/scoping/yields/in segment/main.sdstest new file mode 100644 index 000000000..289c465de --- /dev/null +++ b/tests/resources/scoping/yields/in segment/main.sdstest @@ -0,0 +1,22 @@ +package test.scoping.yields.inSegment + +segment mySegment1() -> before: Int {} + +segment mySegment() -> ( + // $TEST$ target result + »result«: Int +) { + // $TEST$ references result + yield »result« = 1; + + // $TEST$ unresolved + yield »before« = 1; + + // $TEST$ unresolved + yield »after« = 1; + + // $TEST$ unresolved + yield »unresolved« = 1; +} + +segment mySegment2() -> after: Int {}