Skip to content

Commit 090fcc3

Browse files
feat: warn if experimental language features are used (#624)
Closes #108 ### Summary of Changes Warn if experimental language features are used. For the moment, this is only indexed accesses. --------- Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
1 parent d7ff0e2 commit 090fcc3

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { SdsIndexedAccess } from '../generated/ast.js';
2+
import { ValidationAcceptor } from 'langium';
3+
4+
export const CODE_EXPERIMENTAL_LANGUAGE_FEATURE = 'experimental/language-feature';
5+
6+
export const indexedAccessesShouldBeUsedWithCaution = (node: SdsIndexedAccess, accept: ValidationAcceptor): void => {
7+
accept('warning', 'Indexed accesses are experimental and may change without prior notice.', {
8+
node,
9+
code: CODE_EXPERIMENTAL_LANGUAGE_FEATURE,
10+
});
11+
};

src/language/validation/safe-ds-validator.ts

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import {
6363
import { placeholderShouldBeUsed } from './other/declarations/placeholders.js';
6464
import { segmentParameterShouldBeUsed, segmentResultMustBeAssignedExactlyOnce } from './other/declarations/segments.js';
6565
import { lambdaParameterMustNotHaveConstModifier } from './other/expressions/lambdas.js';
66+
import { indexedAccessesShouldBeUsedWithCaution } from './experimentalLanguageFeature.js';
6667

6768
/**
6869
* Register custom validation checks.
@@ -107,6 +108,7 @@ export const registerValidationChecks = function (services: SafeDsServices) {
107108
SdsEnumVariant: [enumVariantMustContainUniqueNames, enumVariantParameterListShouldNotBeEmpty],
108109
SdsExpressionLambda: [expressionLambdaMustContainUniqueNames],
109110
SdsFunction: [functionMustContainUniqueNames, functionResultListShouldNotBeEmpty],
111+
SdsIndexedAccess: [indexedAccessesShouldBeUsedWithCaution],
110112
SdsLambda: [lambdaParameterMustNotHaveConstModifier],
111113
SdsMemberAccess: [memberAccessNullSafetyShouldBeNeeded(services)],
112114
SdsModule: [moduleDeclarationsMustMatchFileKind, moduleWithDeclarationsMustStatePackage],

src/resources/builtins/safeds/lang/coreAnnotations.sdsstub

+2
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ annotation Deprecated(
9090
])
9191
annotation Experimental
9292

93+
@Experimental
9394
@Description("The function has no side effects and returns the same results for the same arguments.")
9495
@Target([AnnotationTarget.Function])
9596
annotation Pure
9697

98+
@Experimental
9799
@Description("The function has no side effects.")
98100
@Target([AnnotationTarget.Function])
99101
annotation NoSideEffects

src/resources/builtins/safeds/lang/documentation.sdsstub

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ annotation Since(
1212
version: String
1313
)
1414

15+
@Experimental
1516
@Description("This parameter should only be used by expert users.")
1617
@Target([AnnotationTarget.Parameter])
1718
annotation Expert
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package tests.validation.experimentalLanguageFeature.indexedAccess
2+
3+
pipeline myPipeline {
4+
// $TEST$ warning "Indexed accesses are experimental and may change without prior notice."
5+
»[1, 2][1]«;
6+
7+
// $TEST$ warning "Indexed accesses are experimental and may change without prior notice."
8+
»{"a": "b"}["a"]«;
9+
}

0 commit comments

Comments
 (0)