From 81fb48d5c12efb1221dc21a7abd53b4b03bb1957 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Fri, 10 Nov 2023 22:16:41 +0100 Subject: [PATCH] feat: mark constraint lists as experimental --- .../language/validation/experimentalLanguageFeatures.ts | 9 +++++++++ .../src/language/validation/safe-ds-validator.ts | 3 ++- .../constraint lists/main.sdstest | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 packages/safe-ds-lang/tests/resources/validation/experimental language feature/constraint lists/main.sdstest diff --git a/packages/safe-ds-lang/src/language/validation/experimentalLanguageFeatures.ts b/packages/safe-ds-lang/src/language/validation/experimentalLanguageFeatures.ts index 94ecfe389..d0ba47cc6 100644 --- a/packages/safe-ds-lang/src/language/validation/experimentalLanguageFeatures.ts +++ b/packages/safe-ds-lang/src/language/validation/experimentalLanguageFeatures.ts @@ -2,6 +2,7 @@ import { isSdsIndexedAccess, isSdsMap, isSdsUnionType, + SdsConstraintList, SdsIndexedAccess, SdsLiteralType, SdsMap, @@ -11,6 +12,14 @@ import { hasContainerOfType, ValidationAcceptor } from 'langium'; export const CODE_EXPERIMENTAL_LANGUAGE_FEATURE = 'experimental/language-feature'; +export const constraintListsShouldBeUsedWithCaution = (node: SdsConstraintList, accept: ValidationAcceptor): void => { + accept('warning', 'Constraint lists & constraints are experimental and may change without prior notice.', { + node, + keyword: 'where', + code: CODE_EXPERIMENTAL_LANGUAGE_FEATURE, + }); +}; + export const indexedAccessesShouldBeUsedWithCaution = (node: SdsIndexedAccess, accept: ValidationAcceptor): void => { if (hasContainerOfType(node.$container, isSdsIndexedAccess)) { return; diff --git a/packages/safe-ds-lang/src/language/validation/safe-ds-validator.ts b/packages/safe-ds-lang/src/language/validation/safe-ds-validator.ts index 837e350df..b55f3ead8 100644 --- a/packages/safe-ds-lang/src/language/validation/safe-ds-validator.ts +++ b/packages/safe-ds-lang/src/language/validation/safe-ds-validator.ts @@ -27,6 +27,7 @@ import { import { singleUseAnnotationsMustNotBeRepeated } from './builtins/repeatable.js'; import { annotationCallMustHaveCorrectTarget, targetShouldNotHaveDuplicateEntries } from './builtins/target.js'; import { + constraintListsShouldBeUsedWithCaution, indexedAccessesShouldBeUsedWithCaution, literalTypesShouldBeUsedWithCaution, mapsShouldBeUsedWithCaution, @@ -221,7 +222,7 @@ export const registerValidationChecks = function (services: SafeDsServices) { classMustNotInheritItself(services), ], SdsClassBody: [classBodyShouldNotBeEmpty], - SdsConstraintList: [constraintListShouldNotBeEmpty], + SdsConstraintList: [constraintListsShouldBeUsedWithCaution, constraintListShouldNotBeEmpty], SdsDeclaration: [ nameMustNotStartWithCodegenPrefix, nameShouldHaveCorrectCasing, diff --git a/packages/safe-ds-lang/tests/resources/validation/experimental language feature/constraint lists/main.sdstest b/packages/safe-ds-lang/tests/resources/validation/experimental language feature/constraint lists/main.sdstest new file mode 100644 index 000000000..d76b39b09 --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/validation/experimental language feature/constraint lists/main.sdstest @@ -0,0 +1,4 @@ +package tests.validation.experimentalLanguageFeature.constraintLists + +// $TEST$ warning "Constraint lists & constraints are experimental and may change without prior notice." +fun myFunction() »where« {}