Skip to content

Commit

Permalink
feat: warn if experimental language features are used (#624)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
lars-reimann and megalinter-bot committed Oct 9, 2023
1 parent d7ff0e2 commit 090fcc3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/language/validation/experimentalLanguageFeature.ts
Original file line number Diff line number Diff line change
@@ -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,
});
};
2 changes: 2 additions & 0 deletions src/language/validation/safe-ds-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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.
Expand Down Expand Up @@ -107,6 +108,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],
Expand Down
2 changes: 2 additions & 0 deletions src/resources/builtins/safeds/lang/coreAnnotations.sdsstub
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/resources/builtins/safeds/lang/documentation.sdsstub
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ annotation Since(
version: String
)

@Experimental
@Description("This parameter should only be used by expert users.")
@Target([AnnotationTarget.Parameter])
annotation Expert
Original file line number Diff line number Diff line change
@@ -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"]«;
}

0 comments on commit 090fcc3

Please sign in to comment.