diff --git a/packages/safe-ds-lang/src/language/validation/experimentalLanguageFeatures.ts b/packages/safe-ds-lang/src/language/validation/experimentalLanguageFeatures.ts index d0ba47cc6..493a00209 100644 --- a/packages/safe-ds-lang/src/language/validation/experimentalLanguageFeatures.ts +++ b/packages/safe-ds-lang/src/language/validation/experimentalLanguageFeatures.ts @@ -1,14 +1,17 @@ +import { hasContainerOfType, ValidationAcceptor } from 'langium'; import { isSdsIndexedAccess, isSdsMap, + isSdsTypeArgumentList, isSdsUnionType, SdsConstraintList, SdsIndexedAccess, SdsLiteralType, SdsMap, + type SdsTypeArgumentList, + type SdsTypeParameterList, SdsUnionType, } from '../generated/ast.js'; -import { hasContainerOfType, ValidationAcceptor } from 'langium'; export const CODE_EXPERIMENTAL_LANGUAGE_FEATURE = 'experimental/language-feature'; @@ -61,3 +64,27 @@ export const unionTypesShouldBeUsedWithCaution = (node: SdsUnionType, accept: Va code: CODE_EXPERIMENTAL_LANGUAGE_FEATURE, }); }; + +export const typeArgumentListsShouldBeUsedWithCaution = ( + node: SdsTypeArgumentList, + accept: ValidationAcceptor, +): void => { + if (hasContainerOfType(node.$container, isSdsTypeArgumentList)) { + return; + } + + accept('warning', 'Type argument lists & type arguments are experimental and may change without prior notice.', { + node, + code: CODE_EXPERIMENTAL_LANGUAGE_FEATURE, + }); +}; + +export const typeParameterListsShouldBeUsedWithCaution = ( + node: SdsTypeParameterList, + accept: ValidationAcceptor, +): void => { + accept('warning', 'Type parameter lists & type parameters are experimental and may change without prior notice.', { + node, + code: CODE_EXPERIMENTAL_LANGUAGE_FEATURE, + }); +}; 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 b55f3ead8..bce28974e 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 @@ -31,6 +31,8 @@ import { indexedAccessesShouldBeUsedWithCaution, literalTypesShouldBeUsedWithCaution, mapsShouldBeUsedWithCaution, + typeArgumentListsShouldBeUsedWithCaution, + typeParameterListsShouldBeUsedWithCaution, unionTypesShouldBeUsedWithCaution, } from './experimentalLanguageFeatures.js'; import { classMustNotInheritItself, classMustOnlyInheritASingleClass } from './inheritance.js'; @@ -316,12 +318,13 @@ export const registerValidationChecks = function (services: SafeDsServices) { segmentShouldBeUsed(services), ], SdsTemplateString: [templateStringMustHaveExpressionBetweenTwoStringParts], + SdsTypeArgumentList: [typeArgumentListsShouldBeUsedWithCaution], SdsTypeParameter: [ typeParameterMustHaveSufficientContext, typeParameterMustNotBeUsedInNestedNamedTypeDeclarations, ], SdsTypeParameterConstraint: [typeParameterConstraintLeftOperandMustBeOwnTypeParameter], - SdsTypeParameterList: [typeParameterListShouldNotBeEmpty], + SdsTypeParameterList: [typeParameterListsShouldBeUsedWithCaution, typeParameterListShouldNotBeEmpty], SdsUnionType: [ unionTypeMustBeUsedInCorrectContext, unionTypeMustHaveTypes, diff --git a/packages/safe-ds-lang/tests/resources/validation/experimental language feature/type argument lists/main.sdstest b/packages/safe-ds-lang/tests/resources/validation/experimental language feature/type argument lists/main.sdstest new file mode 100644 index 000000000..86deacc16 --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/validation/experimental language feature/type argument lists/main.sdstest @@ -0,0 +1,8 @@ + +package tests.validation.experimentalLanguageFeature.typeArgumentLists + +// $TEST$ warning "Type argument lists & type arguments are experimental and may change without prior notice." +class MyClass1(p: MyClass1»<>«) + +// $TEST$ no warning "Type argument lists & type arguments are experimental and may change without prior notice." +class MyClass2(p: MyClass2«>) diff --git a/packages/safe-ds-lang/tests/resources/validation/experimental language feature/type parameter lists/main.sdstest b/packages/safe-ds-lang/tests/resources/validation/experimental language feature/type parameter lists/main.sdstest new file mode 100644 index 000000000..68291ae2b --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/validation/experimental language feature/type parameter lists/main.sdstest @@ -0,0 +1,13 @@ + +package tests.validation.experimentalLanguageFeature.typeParameterLists + +// $TEST$ warning "Type parameter lists & type parameters are experimental and may change without prior notice." +class MyClass»<>« + +// $TEST$ warning "Type parameter lists & type parameters are experimental and may change without prior notice." +enum MyEnum { + MyEnumVariant»<>« +} + +// $TEST$ warning "Type parameter lists & type parameters are experimental and may change without prior notice." +fun myFunction»<>«()