diff --git a/src/language/validation/experimentalLanguageFeatures.ts b/src/language/validation/experimentalLanguageFeatures.ts index a55157f4f..0ecbc0659 100644 --- a/src/language/validation/experimentalLanguageFeatures.ts +++ b/src/language/validation/experimentalLanguageFeatures.ts @@ -1,4 +1,4 @@ -import { SdsIndexedAccess, SdsLiteralType, SdsMap } from '../generated/ast.js'; +import { SdsIndexedAccess, SdsLiteralType, SdsMap, SdsUnionType } from '../generated/ast.js'; import { ValidationAcceptor } from 'langium'; export const CODE_EXPERIMENTAL_LANGUAGE_FEATURE = 'experimental/language-feature'; @@ -23,3 +23,10 @@ export const mapsShouldBeUsedWithCaution = (node: SdsMap, accept: ValidationAcce code: CODE_EXPERIMENTAL_LANGUAGE_FEATURE, }); }; + +export const unionTypesShouldBeUsedWithCaution = (node: SdsUnionType, accept: ValidationAcceptor): void => { + accept('warning', 'Union types are experimental and may change without prior notice.', { + node, + code: CODE_EXPERIMENTAL_LANGUAGE_FEATURE, + }); +}; diff --git a/src/language/validation/safe-ds-validator.ts b/src/language/validation/safe-ds-validator.ts index bf67e2ee4..62c32d440 100644 --- a/src/language/validation/safe-ds-validator.ts +++ b/src/language/validation/safe-ds-validator.ts @@ -98,6 +98,7 @@ import { indexedAccessesShouldBeUsedWithCaution, literalTypesShouldBeUsedWithCaution, mapsShouldBeUsedWithCaution, + unionTypesShouldBeUsedWithCaution, } from './experimentalLanguageFeatures.js'; import { requiredParameterMustNotBeExpert } from './builtins/expert.js'; import { @@ -273,6 +274,7 @@ export const registerValidationChecks = function (services: SafeDsServices) { SdsTypeParameterList: [typeParameterListShouldNotBeEmpty], SdsUnionType: [ unionTypeMustHaveTypes, + unionTypesShouldBeUsedWithCaution, unionTypeShouldNotHaveDuplicateTypes(services), unionTypeShouldNotHaveASingularTypeArgument, ], diff --git a/tests/resources/validation/experimental language feature/union types/main.sdstest b/tests/resources/validation/experimental language feature/union types/main.sdstest new file mode 100644 index 000000000..1fe244879 --- /dev/null +++ b/tests/resources/validation/experimental language feature/union types/main.sdstest @@ -0,0 +1,6 @@ +package tests.validation.experimentalLanguageFeature.unionTypes + +fun myFunction( + // $TEST$ warning "Union types are experimental and may change without prior notice." + p: »union<>« +)