Skip to content

Commit 4656c25

Browse files
authored
feat: mark union types as experimental (#676)
Closes #674 ### Summary of Changes Using a union type now shows a warning that this language feature is experimental.
1 parent 867bae3 commit 4656c25

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/language/validation/experimentalLanguageFeatures.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SdsIndexedAccess, SdsLiteralType, SdsMap } from '../generated/ast.js';
1+
import { SdsIndexedAccess, SdsLiteralType, SdsMap, SdsUnionType } from '../generated/ast.js';
22
import { ValidationAcceptor } from 'langium';
33

44
export const CODE_EXPERIMENTAL_LANGUAGE_FEATURE = 'experimental/language-feature';
@@ -23,3 +23,10 @@ export const mapsShouldBeUsedWithCaution = (node: SdsMap, accept: ValidationAcce
2323
code: CODE_EXPERIMENTAL_LANGUAGE_FEATURE,
2424
});
2525
};
26+
27+
export const unionTypesShouldBeUsedWithCaution = (node: SdsUnionType, accept: ValidationAcceptor): void => {
28+
accept('warning', 'Union types are experimental and may change without prior notice.', {
29+
node,
30+
code: CODE_EXPERIMENTAL_LANGUAGE_FEATURE,
31+
});
32+
};

src/language/validation/safe-ds-validator.ts

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import {
9898
indexedAccessesShouldBeUsedWithCaution,
9999
literalTypesShouldBeUsedWithCaution,
100100
mapsShouldBeUsedWithCaution,
101+
unionTypesShouldBeUsedWithCaution,
101102
} from './experimentalLanguageFeatures.js';
102103
import { requiredParameterMustNotBeExpert } from './builtins/expert.js';
103104
import {
@@ -273,6 +274,7 @@ export const registerValidationChecks = function (services: SafeDsServices) {
273274
SdsTypeParameterList: [typeParameterListShouldNotBeEmpty],
274275
SdsUnionType: [
275276
unionTypeMustHaveTypes,
277+
unionTypesShouldBeUsedWithCaution,
276278
unionTypeShouldNotHaveDuplicateTypes(services),
277279
unionTypeShouldNotHaveASingularTypeArgument,
278280
],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package tests.validation.experimentalLanguageFeature.unionTypes
2+
3+
fun myFunction(
4+
// $TEST$ warning "Union types are experimental and may change without prior notice."
5+
p: »union<>«
6+
)

0 commit comments

Comments
 (0)