From e3148da12164436ac39680238ebb71ed857a378d Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Sat, 21 Oct 2023 09:42:16 +0200 Subject: [PATCH] fix: mark map literals as experimental --- src/language/validation/experimentalLanguageFeatures.ts | 9 ++++++++- src/language/validation/safe-ds-validator.ts | 6 +++++- .../resources/scoping/member accesses/skip-main.sdstest | 7 ------- .../experimental language feature/maps/main.sdstest | 6 ++++++ 4 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 tests/resources/validation/experimental language feature/maps/main.sdstest diff --git a/src/language/validation/experimentalLanguageFeatures.ts b/src/language/validation/experimentalLanguageFeatures.ts index 9e8850adb..c74d9cf6b 100644 --- a/src/language/validation/experimentalLanguageFeatures.ts +++ b/src/language/validation/experimentalLanguageFeatures.ts @@ -1,4 +1,4 @@ -import { SdsIndexedAccess } from '../generated/ast.js'; +import { SdsIndexedAccess, SdsMap } from '../generated/ast.js'; import { ValidationAcceptor } from 'langium'; export const CODE_EXPERIMENTAL_LANGUAGE_FEATURE = 'experimental/language-feature'; @@ -9,3 +9,10 @@ export const indexedAccessesShouldBeUsedWithCaution = (node: SdsIndexedAccess, a code: CODE_EXPERIMENTAL_LANGUAGE_FEATURE, }); }; + +export const mapsShouldBeUsedWithCaution = (node: SdsMap, accept: ValidationAcceptor): void => { + accept('warning', 'Map literals 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 1ebe702b5..cdee6bf0d 100644 --- a/src/language/validation/safe-ds-validator.ts +++ b/src/language/validation/safe-ds-validator.ts @@ -90,7 +90,10 @@ import { lambdaMustBeAssignedToTypedParameter, lambdaParameterMustNotHaveConstModifier, } from './other/expressions/lambdas.js'; -import { indexedAccessesShouldBeUsedWithCaution } from './experimentalLanguageFeatures.js'; +import { + indexedAccessesShouldBeUsedWithCaution, + mapsShouldBeUsedWithCaution +} from './experimentalLanguageFeatures.js'; import { requiredParameterMustNotBeExpert } from './builtins/expert.js'; import { annotationCallArgumentsMustBeConstant, @@ -197,6 +200,7 @@ export const registerValidationChecks = function (services: SafeDsServices) { lambdaParametersMustNotBeAnnotated, lambdaParameterMustNotHaveConstModifier, ], + SdsMap: [mapsShouldBeUsedWithCaution], SdsMemberAccess: [ memberAccessMustBeNullSafeIfReceiverIsNullable(services), memberAccessNullSafetyShouldBeNeeded(services), diff --git a/tests/resources/scoping/member accesses/skip-main.sdstest b/tests/resources/scoping/member accesses/skip-main.sdstest index eaadc197c..af6791263 100644 --- a/tests/resources/scoping/member accesses/skip-main.sdstest +++ b/tests/resources/scoping/member accesses/skip-main.sdstest @@ -500,13 +500,6 @@ class SubClassForHiding sub SuperClassForHiding { static fun staticMethodForHiding() } -class ClassForResultMemberAccess() { - attr result: Int -} -enum EnumForResultMemberAccess { - result -} - // Access to own members ------------------------------------------------------- diff --git a/tests/resources/validation/experimental language feature/maps/main.sdstest b/tests/resources/validation/experimental language feature/maps/main.sdstest new file mode 100644 index 000000000..24a13dc14 --- /dev/null +++ b/tests/resources/validation/experimental language feature/maps/main.sdstest @@ -0,0 +1,6 @@ +package tests.validation.experimentalLanguageFeature.maps + +pipeline myPipeline { + // $TEST$ warning "Map literals are experimental and may change without prior notice." + »{"a": "b"}«; +}