Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: warn if experimental language features are used #624

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]«;
}