Skip to content

Commit

Permalink
feat: mark type parameter lists and type argument lists as experiment…
Browse files Browse the repository at this point in the history
…al (#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.
  • Loading branch information
lars-reimann authored Nov 11, 2023
1 parent e60e456 commit f1a052a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {
indexedAccessesShouldBeUsedWithCaution,
literalTypesShouldBeUsedWithCaution,
mapsShouldBeUsedWithCaution,
typeArgumentListsShouldBeUsedWithCaution,
typeParameterListsShouldBeUsedWithCaution,
unionTypesShouldBeUsedWithCaution,
} from './experimentalLanguageFeatures.js';
import { classMustNotInheritItself, classMustOnlyInheritASingleClass } from './inheritance.js';
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T>(p: MyClass2<MyClass1»<>«>)
Original file line number Diff line number Diff line change
@@ -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»<>«()

0 comments on commit f1a052a

Please sign in to comment.