Skip to content

Commit f1a052a

Browse files
authored
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.
1 parent e60e456 commit f1a052a

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

packages/safe-ds-lang/src/language/validation/experimentalLanguageFeatures.ts

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
import { hasContainerOfType, ValidationAcceptor } from 'langium';
12
import {
23
isSdsIndexedAccess,
34
isSdsMap,
5+
isSdsTypeArgumentList,
46
isSdsUnionType,
57
SdsConstraintList,
68
SdsIndexedAccess,
79
SdsLiteralType,
810
SdsMap,
11+
type SdsTypeArgumentList,
12+
type SdsTypeParameterList,
913
SdsUnionType,
1014
} from '../generated/ast.js';
11-
import { hasContainerOfType, ValidationAcceptor } from 'langium';
1215

1316
export const CODE_EXPERIMENTAL_LANGUAGE_FEATURE = 'experimental/language-feature';
1417

@@ -61,3 +64,27 @@ export const unionTypesShouldBeUsedWithCaution = (node: SdsUnionType, accept: Va
6164
code: CODE_EXPERIMENTAL_LANGUAGE_FEATURE,
6265
});
6366
};
67+
68+
export const typeArgumentListsShouldBeUsedWithCaution = (
69+
node: SdsTypeArgumentList,
70+
accept: ValidationAcceptor,
71+
): void => {
72+
if (hasContainerOfType(node.$container, isSdsTypeArgumentList)) {
73+
return;
74+
}
75+
76+
accept('warning', 'Type argument lists & type arguments are experimental and may change without prior notice.', {
77+
node,
78+
code: CODE_EXPERIMENTAL_LANGUAGE_FEATURE,
79+
});
80+
};
81+
82+
export const typeParameterListsShouldBeUsedWithCaution = (
83+
node: SdsTypeParameterList,
84+
accept: ValidationAcceptor,
85+
): void => {
86+
accept('warning', 'Type parameter lists & type parameters are experimental and may change without prior notice.', {
87+
node,
88+
code: CODE_EXPERIMENTAL_LANGUAGE_FEATURE,
89+
});
90+
};

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import {
3131
indexedAccessesShouldBeUsedWithCaution,
3232
literalTypesShouldBeUsedWithCaution,
3333
mapsShouldBeUsedWithCaution,
34+
typeArgumentListsShouldBeUsedWithCaution,
35+
typeParameterListsShouldBeUsedWithCaution,
3436
unionTypesShouldBeUsedWithCaution,
3537
} from './experimentalLanguageFeatures.js';
3638
import { classMustNotInheritItself, classMustOnlyInheritASingleClass } from './inheritance.js';
@@ -316,12 +318,13 @@ export const registerValidationChecks = function (services: SafeDsServices) {
316318
segmentShouldBeUsed(services),
317319
],
318320
SdsTemplateString: [templateStringMustHaveExpressionBetweenTwoStringParts],
321+
SdsTypeArgumentList: [typeArgumentListsShouldBeUsedWithCaution],
319322
SdsTypeParameter: [
320323
typeParameterMustHaveSufficientContext,
321324
typeParameterMustNotBeUsedInNestedNamedTypeDeclarations,
322325
],
323326
SdsTypeParameterConstraint: [typeParameterConstraintLeftOperandMustBeOwnTypeParameter],
324-
SdsTypeParameterList: [typeParameterListShouldNotBeEmpty],
327+
SdsTypeParameterList: [typeParameterListsShouldBeUsedWithCaution, typeParameterListShouldNotBeEmpty],
325328
SdsUnionType: [
326329
unionTypeMustBeUsedInCorrectContext,
327330
unionTypeMustHaveTypes,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
package tests.validation.experimentalLanguageFeature.typeArgumentLists
3+
4+
// $TEST$ warning "Type argument lists & type arguments are experimental and may change without prior notice."
5+
class MyClass1(p: MyClass1»<>«)
6+
7+
// $TEST$ no warning "Type argument lists & type arguments are experimental and may change without prior notice."
8+
class MyClass2<T>(p: MyClass2<MyClass1»<>«>)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
package tests.validation.experimentalLanguageFeature.typeParameterLists
3+
4+
// $TEST$ warning "Type parameter lists & type parameters are experimental and may change without prior notice."
5+
class MyClass»<>«
6+
7+
// $TEST$ warning "Type parameter lists & type parameters are experimental and may change without prior notice."
8+
enum MyEnum {
9+
MyEnumVariant»<>«
10+
}
11+
12+
// $TEST$ warning "Type parameter lists & type parameters are experimental and may change without prior notice."
13+
fun myFunction»<>«()

0 commit comments

Comments
 (0)