From 66f5ee8d5df227d1d570afd7af43afdf01dd5480 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Mon, 9 Oct 2023 21:12:33 +0200 Subject: [PATCH 1/3] feat: mark some builtin declarations as experimental --- src/resources/builtins/safeds/lang/coreAnnotations.sdsstub | 2 ++ src/resources/builtins/safeds/lang/documentation.sdsstub | 1 + 2 files changed, 3 insertions(+) diff --git a/src/resources/builtins/safeds/lang/coreAnnotations.sdsstub b/src/resources/builtins/safeds/lang/coreAnnotations.sdsstub index 71602d7ae..330c7cc53 100644 --- a/src/resources/builtins/safeds/lang/coreAnnotations.sdsstub +++ b/src/resources/builtins/safeds/lang/coreAnnotations.sdsstub @@ -90,10 +90,12 @@ annotation Deprecated( ]) annotation Experimental +@Experimental @Description("The function has no side effects and returns the same results for the same arguments.") @Target([AnnotationTarget.Function]) annotation Pure +@Experimental @Description("The function has no side effects.") @Target([AnnotationTarget.Function]) annotation NoSideEffects diff --git a/src/resources/builtins/safeds/lang/documentation.sdsstub b/src/resources/builtins/safeds/lang/documentation.sdsstub index 455dbcbdf..0d714f493 100644 --- a/src/resources/builtins/safeds/lang/documentation.sdsstub +++ b/src/resources/builtins/safeds/lang/documentation.sdsstub @@ -12,6 +12,7 @@ annotation Since( version: String ) +@Experimental @Description("This parameter should only be used by expert users.") @Target([AnnotationTarget.Parameter]) annotation Expert From b11d80e8587bdb0643496698ce14ae4b41a38eb3 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Mon, 9 Oct 2023 22:17:08 +0200 Subject: [PATCH 2/3] feat: warn if experimental language features are used --- .../validation/experimentalLanguageFeature.ts | 11 +++++++++++ src/language/validation/safe-ds-validator.ts | 10 ++++++++-- .../indexed access/main.sdstest | 9 +++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/language/validation/experimentalLanguageFeature.ts create mode 100644 tests/resources/validation/experimental language feature/indexed access/main.sdstest diff --git a/src/language/validation/experimentalLanguageFeature.ts b/src/language/validation/experimentalLanguageFeature.ts new file mode 100644 index 000000000..9e8850adb --- /dev/null +++ b/src/language/validation/experimentalLanguageFeature.ts @@ -0,0 +1,11 @@ +import { SdsIndexedAccess } from '../generated/ast.js'; +import { ValidationAcceptor } from 'langium'; + +export const CODE_EXPERIMENTAL_LANGUAGE_FEATURE = 'experimental/language-feature'; + +export const indexedAccessesShouldBeUsedWithCaution = (node: SdsIndexedAccess, accept: ValidationAcceptor): void => { + accept('warning', 'Indexed accesses are experimental and may change without prior notice.', { + node, + code: CODE_EXPERIMENTAL_LANGUAGE_FEATURE, + }); +}; diff --git a/src/language/validation/safe-ds-validator.ts b/src/language/validation/safe-ds-validator.ts index 0ec0351c1..5c902a577 100644 --- a/src/language/validation/safe-ds-validator.ts +++ b/src/language/validation/safe-ds-validator.ts @@ -36,8 +36,12 @@ import { templateStringMustHaveExpressionBetweenTwoStringParts } from './other/e import { yieldMustNotBeUsedInPipeline } from './other/statements/assignments.js'; import { attributeMustHaveTypeHint, parameterMustHaveTypeHint, resultMustHaveTypeHint } from './types.js'; import { moduleDeclarationsMustMatchFileKind, moduleWithDeclarationsMustStatePackage } from './other/modules.js'; -import { typeParameterConstraintLeftOperandMustBeOwnTypeParameter } from './other/declarations/typeParameterConstraints.js'; -import { parameterListMustNotHaveRequiredParametersAfterOptionalParameters } from './other/declarations/parameterLists.js'; +import { + typeParameterConstraintLeftOperandMustBeOwnTypeParameter, +} from './other/declarations/typeParameterConstraints.js'; +import { + parameterListMustNotHaveRequiredParametersAfterOptionalParameters, +} from './other/declarations/parameterLists.js'; import { unionTypeMustHaveTypeArguments } from './other/types/unionTypes.js'; import { callableTypeMustNotHaveOptionalParameters, @@ -63,6 +67,7 @@ import { import { placeholderShouldBeUsed } from './other/declarations/placeholders.js'; import { segmentParameterShouldBeUsed, segmentResultMustBeAssignedExactlyOnce } from './other/declarations/segments.js'; import { lambdaParameterMustNotHaveConstModifier } from './other/expressions/lambdas.js'; +import { indexedAccessesShouldBeUsedWithCaution } from './experimentalLanguageFeature.js'; /** * Register custom validation checks. @@ -107,6 +112,7 @@ export const registerValidationChecks = function (services: SafeDsServices) { SdsEnumVariant: [enumVariantMustContainUniqueNames, enumVariantParameterListShouldNotBeEmpty], SdsExpressionLambda: [expressionLambdaMustContainUniqueNames], SdsFunction: [functionMustContainUniqueNames, functionResultListShouldNotBeEmpty], + SdsIndexedAccess: [indexedAccessesShouldBeUsedWithCaution], SdsLambda: [lambdaParameterMustNotHaveConstModifier], SdsMemberAccess: [memberAccessNullSafetyShouldBeNeeded(services)], SdsModule: [moduleDeclarationsMustMatchFileKind, moduleWithDeclarationsMustStatePackage], diff --git a/tests/resources/validation/experimental language feature/indexed access/main.sdstest b/tests/resources/validation/experimental language feature/indexed access/main.sdstest new file mode 100644 index 000000000..4c4a858a9 --- /dev/null +++ b/tests/resources/validation/experimental language feature/indexed access/main.sdstest @@ -0,0 +1,9 @@ +package tests.validation.experimentalLanguageFeature.indexedAccess + +pipeline myPipeline { + // $TEST$ warning "Indexed accesses are experimental and may change without prior notice." + »[1, 2][1]«; + + // $TEST$ warning "Indexed accesses are experimental and may change without prior notice." + »{"a": "b"}["a"]«; +} From 560064b12a0c7b2d640a2c0edb4b27c862c06e19 Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Mon, 9 Oct 2023 20:20:10 +0000 Subject: [PATCH 3/3] style: apply automated linter fixes --- src/language/validation/safe-ds-validator.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/language/validation/safe-ds-validator.ts b/src/language/validation/safe-ds-validator.ts index 5c902a577..61d5429d7 100644 --- a/src/language/validation/safe-ds-validator.ts +++ b/src/language/validation/safe-ds-validator.ts @@ -36,12 +36,8 @@ import { templateStringMustHaveExpressionBetweenTwoStringParts } from './other/e import { yieldMustNotBeUsedInPipeline } from './other/statements/assignments.js'; import { attributeMustHaveTypeHint, parameterMustHaveTypeHint, resultMustHaveTypeHint } from './types.js'; import { moduleDeclarationsMustMatchFileKind, moduleWithDeclarationsMustStatePackage } from './other/modules.js'; -import { - typeParameterConstraintLeftOperandMustBeOwnTypeParameter, -} from './other/declarations/typeParameterConstraints.js'; -import { - parameterListMustNotHaveRequiredParametersAfterOptionalParameters, -} from './other/declarations/parameterLists.js'; +import { typeParameterConstraintLeftOperandMustBeOwnTypeParameter } from './other/declarations/typeParameterConstraints.js'; +import { parameterListMustNotHaveRequiredParametersAfterOptionalParameters } from './other/declarations/parameterLists.js'; import { unionTypeMustHaveTypeArguments } from './other/types/unionTypes.js'; import { callableTypeMustNotHaveOptionalParameters,