From f1a052a74ed4dccbc4e18cb944adc8c50879c10c Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Sat, 11 Nov 2023 10:37:51 +0100 Subject: [PATCH] feat: mark type parameter lists and type argument lists as experimental (#755) Closes #753 ### Summary of Changes Mark type parameter lists and type argument lists as experimental. This also applies to the contained type parameters and type arguments. --- .../experimentalLanguageFeatures.ts | 29 ++++++++++++++++++- .../language/validation/safe-ds-validator.ts | 5 +++- .../type argument lists/main.sdstest | 8 +++++ .../type parameter lists/main.sdstest | 13 +++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 packages/safe-ds-lang/tests/resources/validation/experimental language feature/type argument lists/main.sdstest create mode 100644 packages/safe-ds-lang/tests/resources/validation/experimental language feature/type parameter lists/main.sdstest 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»<>«()