Skip to content

Commit

Permalink
feat: mark union types as experimental (#676)
Browse files Browse the repository at this point in the history
Closes #674

### Summary of Changes

Using a union type now shows a warning that this language feature is
experimental.
  • Loading branch information
lars-reimann authored Oct 22, 2023
1 parent 867bae3 commit 4656c25
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/language/validation/experimentalLanguageFeatures.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
});
};
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 @@ -98,6 +98,7 @@ import {
indexedAccessesShouldBeUsedWithCaution,
literalTypesShouldBeUsedWithCaution,
mapsShouldBeUsedWithCaution,
unionTypesShouldBeUsedWithCaution,
} from './experimentalLanguageFeatures.js';
import { requiredParameterMustNotBeExpert } from './builtins/expert.js';
import {
Expand Down Expand Up @@ -273,6 +274,7 @@ export const registerValidationChecks = function (services: SafeDsServices) {
SdsTypeParameterList: [typeParameterListShouldNotBeEmpty],
SdsUnionType: [
unionTypeMustHaveTypes,
unionTypesShouldBeUsedWithCaution,
unionTypeShouldNotHaveDuplicateTypes(services),
unionTypeShouldNotHaveASingularTypeArgument,
],
Expand Down
Original file line number Diff line number Diff line change
@@ -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<>«
)

0 comments on commit 4656c25

Please sign in to comment.