From f6330a1d9957d962187941a213c39535e1ab2901 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Mon, 15 Apr 2024 12:37:22 +0200 Subject: [PATCH] refactor: rename "type parameter type" to "type variable" (#1051) ### Summary of Changes Rename the type "type parameter type" to "type variable". This is shorter, less cumbersome, and better highlights that this type can be substituted by another type. --- .../generation/safe-ds-markdown-generator.ts | 4 +- .../scoping/safe-ds-scope-provider.ts | 4 +- .../safe-ds-lang/src/language/typing/model.ts | 8 ++-- .../language/typing/safe-ds-type-checker.ts | 24 +++++----- .../language/typing/safe-ds-type-computer.ts | 46 +++++++++---------- .../language/typing/safe-ds-type-factory.ts | 6 +-- .../src/language/validation/types.ts | 8 ++-- .../tests/language/typing/model.test.ts | 46 ++++++++----------- .../type checker/isSubOrSupertypeOf.test.ts | 4 +- .../main.sdsdev | 2 +- .../main.sdsdev | 2 +- .../main.sdsdev | 2 +- .../main.sdsdev | 2 +- .../main.sdsdev | 2 +- .../main.sdsdev | 2 +- .../main.sdsdev | 2 +- .../main.sdsdev | 2 +- .../main.sdsdev | 2 +- 18 files changed, 81 insertions(+), 87 deletions(-) rename packages/safe-ds-lang/tests/resources/typing/highest common subtype/{class type and type parameter type => class type and type variable}/main.sdsdev (95%) rename packages/safe-ds-lang/tests/resources/typing/highest common subtype/{enum type and type parameter type => enum type and type variable}/main.sdsdev (95%) rename packages/safe-ds-lang/tests/resources/typing/highest common subtype/{enum variant type and type parameter type => enum variant type and type variable}/main.sdsdev (99%) rename packages/safe-ds-lang/tests/resources/typing/highest common subtype/{type parameter type and type parameter type => type variable and type variable}/main.sdsdev (90%) rename packages/safe-ds-lang/tests/resources/typing/lowest common supertype/{class type and type parameter type => class type and type variable}/main.sdsdev (89%) rename packages/safe-ds-lang/tests/resources/typing/lowest common supertype/{enum type and type parameter type => enum type and type variable}/main.sdsdev (92%) rename packages/safe-ds-lang/tests/resources/typing/lowest common supertype/{enum variant type and type parameter type => enum variant type and type variable}/main.sdsdev (98%) rename packages/safe-ds-lang/tests/resources/typing/lowest common supertype/{literal type and type parameter type => literal type and type variable}/main.sdsdev (90%) rename packages/safe-ds-lang/tests/resources/typing/lowest common supertype/{type parameter type and type parameter type => type variable and type variable}/main.sdsdev (93%) diff --git a/packages/safe-ds-lang/src/language/generation/safe-ds-markdown-generator.ts b/packages/safe-ds-lang/src/language/generation/safe-ds-markdown-generator.ts index fca92eccd..856d69937 100644 --- a/packages/safe-ds-lang/src/language/generation/safe-ds-markdown-generator.ts +++ b/packages/safe-ds-lang/src/language/generation/safe-ds-markdown-generator.ts @@ -46,7 +46,7 @@ import { SafeDsDocumentationProvider } from '../documentation/safe-ds-documentat import { SafeDsAnnotations } from '../builtins/safe-ds-annotations.js'; import { isEmpty } from '../../helpers/collections.js'; import { SafeDsTypeComputer } from '../typing/safe-ds-type-computer.js'; -import { NamedType, Type, TypeParameterType } from '../typing/model.js'; +import { NamedType, Type, TypeVariable } from '../typing/model.js'; import path from 'path'; import { addLinePrefix, removeLinePrefix } from '../../helpers/strings.js'; import { expandToStringLF } from 'langium/generate'; @@ -544,7 +544,7 @@ export class SafeDsMarkdownGenerator { } private renderType(type: Type, knownPaths: Set): string { - if (type instanceof NamedType && !(type instanceof TypeParameterType)) { + if (type instanceof NamedType && !(type instanceof TypeVariable)) { const realPath = AstUtils.getDocument(type.declaration).uri.fsPath; // When generating documentation for the standard library declarations in the `src` folder, references are // resolved to the `lib` folder. To still create links, we also check this augmented path. diff --git a/packages/safe-ds-lang/src/language/scoping/safe-ds-scope-provider.ts b/packages/safe-ds-lang/src/language/scoping/safe-ds-scope-provider.ts index 07b70f44a..66e53b183 100644 --- a/packages/safe-ds-lang/src/language/scoping/safe-ds-scope-provider.ts +++ b/packages/safe-ds-lang/src/language/scoping/safe-ds-scope-provider.ts @@ -72,7 +72,7 @@ import { } from '../helpers/nodeProperties.js'; import { SafeDsNodeMapper } from '../helpers/safe-ds-node-mapper.js'; import { SafeDsServices } from '../safe-ds-module.js'; -import { ClassType, EnumVariantType, LiteralType, TypeParameterType } from '../typing/model.js'; +import { ClassType, EnumVariantType, LiteralType, TypeVariable } from '../typing/model.js'; import type { SafeDsClassHierarchy } from '../typing/safe-ds-class-hierarchy.js'; import { SafeDsTypeComputer } from '../typing/safe-ds-type-computer.js'; import { SafeDsPackageManager } from '../workspace/safe-ds-package-manager.js'; @@ -244,7 +244,7 @@ export class SafeDsScopeProvider extends DefaultScopeProvider { let receiverType = this.typeComputer.computeType(node.receiver); if (receiverType instanceof LiteralType) { receiverType = this.typeComputer.computeClassTypeForLiteralType(receiverType); - } else if (receiverType instanceof TypeParameterType) { + } else if (receiverType instanceof TypeVariable) { receiverType = this.typeComputer.computeUpperBound(receiverType); } diff --git a/packages/safe-ds-lang/src/language/typing/model.ts b/packages/safe-ds-lang/src/language/typing/model.ts index d0c4a5bd4..1d7226f36 100644 --- a/packages/safe-ds-lang/src/language/typing/model.ts +++ b/packages/safe-ds-lang/src/language/typing/model.ts @@ -532,7 +532,7 @@ export class EnumVariantType extends NamedType { } } -export class TypeParameterType extends NamedType { +export class TypeVariable extends NamedType { override readonly isFullySubstituted = false; constructor( @@ -545,7 +545,7 @@ export class TypeParameterType extends NamedType { override equals(other: unknown): boolean { if (other === this) { return true; - } else if (!(other instanceof TypeParameterType)) { + } else if (!(other instanceof TypeVariable)) { return false; } @@ -564,12 +564,12 @@ export class TypeParameterType extends NamedType { } } - override withExplicitNullability(isExplicitlyNullable: boolean): TypeParameterType { + override withExplicitNullability(isExplicitlyNullable: boolean): TypeVariable { if (this.isExplicitlyNullable === isExplicitlyNullable) { return this; } - return new TypeParameterType(this.declaration, isExplicitlyNullable); + return new TypeVariable(this.declaration, isExplicitlyNullable); } } diff --git a/packages/safe-ds-lang/src/language/typing/safe-ds-type-checker.ts b/packages/safe-ds-lang/src/language/typing/safe-ds-type-checker.ts index b0b89a5c3..62b0e1c91 100644 --- a/packages/safe-ds-lang/src/language/typing/safe-ds-type-checker.ts +++ b/packages/safe-ds-lang/src/language/typing/safe-ds-type-checker.ts @@ -12,7 +12,7 @@ import { NamedTupleType, StaticType, Type, - TypeParameterType, + TypeVariable, UnionType, UnknownType, } from './model.js'; @@ -58,13 +58,13 @@ export class SafeDsTypeChecker { } // Handle type parameter types - if (other instanceof TypeParameterType) { + if (other instanceof TypeVariable) { if (type.isExplicitlyNullable && !other.isExplicitlyNullable) { return false; } // `T` can always be assigned to `T` or some type parameter it is bounded by - if (type instanceof TypeParameterType && this.typeParameterIsBoundedByTypeParameter(type, other)) { + if (type instanceof TypeVariable && this.typeVariableIsBoundedByTypeVariable(type, other)) { return true; } @@ -94,22 +94,22 @@ export class SafeDsTypeChecker { return this.namedTupleTypeIsSubtypeOf(type, other, options); } else if (type instanceof StaticType) { return this.staticTypeIsSubtypeOf(type, other, options); - } else if (type instanceof TypeParameterType) { - return this.typeParameterTypeIsSubtypeOf(type, other, options); + } else if (type instanceof TypeVariable) { + return this.typeVariableIsSubtypeOf(type, other, options); } /* c8 ignore start */ else { throw new Error(`Unexpected type: ${type.constructor.name}`); } /* c8 ignore stop */ }; - private typeParameterIsBoundedByTypeParameter(type: TypeParameterType, other: TypeParameterType): boolean { + private typeVariableIsBoundedByTypeVariable(type: TypeVariable, other: TypeVariable): boolean { let current: Type = type; - while (current instanceof TypeParameterType) { + while (current instanceof TypeVariable) { if (current.declaration === other.declaration) { return true; } - current = this.typeComputer().computeUpperBound(current, { stopAtTypeParameterType: true }); + current = this.typeComputer().computeUpperBound(current, { stopAtTypeVariable: true }); } return false; @@ -313,7 +313,7 @@ export class SafeDsTypeChecker { } } - private typeParameterTypeIsSubtypeOf(type: TypeParameterType, other: Type, options: TypeCheckOptions): boolean { + private typeVariableIsSubtypeOf(type: TypeVariable, other: Type, options: TypeCheckOptions): boolean { const upperBound = this.typeComputer().computeUpperBound(type); return this.isSubtypeOf(upperBound, other, options); } @@ -358,7 +358,7 @@ export class SafeDsTypeChecker { canBeNull = (type: Type): boolean => { if (type.isExplicitlyNullable) { return true; - } else if (type instanceof TypeParameterType) { + } else if (type instanceof TypeVariable) { const upperBound = this.typeComputer().computeUpperBound(type); return upperBound.isExplicitlyNullable; } else { @@ -392,7 +392,7 @@ export class SafeDsTypeChecker { /** * Checks whether {@link type} is some kind of list (with any element type). */ - isList(type: Type): type is ClassType | TypeParameterType { + isList(type: Type): type is ClassType | TypeVariable { const listOrNull = this.coreTypes.List(UnknownType).withExplicitNullability(true); return ( @@ -407,7 +407,7 @@ export class SafeDsTypeChecker { /** * Checks whether {@link type} is some kind of map (with any key/value types). */ - isMap(type: Type): type is ClassType | TypeParameterType { + isMap(type: Type): type is ClassType | TypeVariable { const mapOrNull = this.coreTypes.Map(UnknownType, UnknownType).withExplicitNullability(true); return ( diff --git a/packages/safe-ds-lang/src/language/typing/safe-ds-type-computer.ts b/packages/safe-ds-lang/src/language/typing/safe-ds-type-computer.ts index 55feca517..bb9c73bb8 100644 --- a/packages/safe-ds-lang/src/language/typing/safe-ds-type-computer.ts +++ b/packages/safe-ds-lang/src/language/typing/safe-ds-type-computer.ts @@ -103,7 +103,7 @@ import { StaticType, Type, TypeParameterSubstitutions, - TypeParameterType, + TypeVariable, UnionType, UnknownType, } from './model.js'; @@ -249,7 +249,7 @@ export class SafeDsTypeComputer { } else if (isSdsSegment(node)) { return this.computeTypeOfCallableWithManifestTypes(node, state); } else if (isSdsTypeParameter(node)) { - return this.factory.createTypeParameterType(node, false); + return this.factory.createTypeVariable(node, false); } /* c8 ignore start */ else { return UnknownType; } /* c8 ignore stop */ @@ -535,7 +535,7 @@ export class SafeDsTypeComputer { private computeTypeOfIndexedAccess(node: SdsIndexedAccess, state: ComputeTypeState): Type { const receiverType = this.computeTypeWithRecursionCheck(node.receiver, state); - if (!(receiverType instanceof ClassType) && !(receiverType instanceof TypeParameterType)) { + if (!(receiverType instanceof ClassType) && !(receiverType instanceof TypeVariable)) { return UnknownType; } @@ -754,19 +754,19 @@ export class SafeDsTypeComputer { * invalid upper bounds are specified, but are invalid (e.g. because of an unresolved reference or a cycle), * `unknown` is returned. The result is simplified as much as possible. */ - computeUpperBound(nodeOrType: SdsTypeParameter | TypeParameterType, options: ComputeUpperBoundOptions = {}): Type { - let type: TypeParameterType; - if (nodeOrType instanceof TypeParameterType) { + computeUpperBound(nodeOrType: SdsTypeParameter | TypeVariable, options: ComputeUpperBoundOptions = {}): Type { + let type: TypeVariable; + if (nodeOrType instanceof TypeVariable) { type = nodeOrType; } else { - type = this.computeType(nodeOrType) as TypeParameterType; + type = this.computeType(nodeOrType) as TypeVariable; } const result = this.doComputeUpperBound(type, options); return result.withExplicitNullability(result.isExplicitlyNullable || type.isExplicitlyNullable); } - private doComputeUpperBound(type: TypeParameterType, options: ComputeUpperBoundOptions): Type { + private doComputeUpperBound(type: TypeVariable, options: ComputeUpperBoundOptions): Type { const upperBound = type.declaration.upperBound; if (!upperBound) { return this.coreTypes.AnyOrNull; @@ -775,7 +775,7 @@ export class SafeDsTypeComputer { const boundType = this.computeType(upperBound); if (!(boundType instanceof NamedType)) { return UnknownType; - } else if (options.stopAtTypeParameterType || !(boundType instanceof TypeParameterType)) { + } else if (options.stopAtTypeVariable || !(boundType instanceof TypeVariable)) { return boundType; } else { return this.doComputeUpperBound(boundType, options); @@ -937,7 +937,7 @@ export class SafeDsTypeComputer { // Clamp to upper bound const upperBound = this.computeUpperBound(typeParameter, { - stopAtTypeParameterType: true, + stopAtTypeVariable: true, }).substituteTypeParameters(state.substitutions); if (!this.typeChecker.isSubtypeOf(newSubstitution, upperBound)) { @@ -956,7 +956,7 @@ export class SafeDsTypeComputer { currentVariance: Variance, state: ComputeSubstitutionsForParametersState, ) { - if (argumentType instanceof TypeParameterType && state.substitutions.has(argumentType.declaration)) { + if (argumentType instanceof TypeVariable && state.substitutions.has(argumentType.declaration)) { // Can happen for lambdas without manifest parameter types. We gain no information here. return; } else if (parameterType instanceof CallableType && argumentType instanceof CallableType) { @@ -1029,7 +1029,7 @@ export class SafeDsTypeComputer { ); } } - } else if (parameterType instanceof TypeParameterType) { + } else if (parameterType instanceof TypeVariable) { const currentSubstitution = state.substitutions.get(parameterType.declaration); const remainingVariance = state.remainingVariances.get(parameterType.declaration); if (!currentSubstitution) { @@ -1076,8 +1076,8 @@ export class SafeDsTypeComputer { return simplifiedTypes[0]!; } - // Replace type parameter types by their upper bound - const replacedTypes = this.replaceTypeParameterTypesWithUpperBound(simplifiedTypes); + // Replace type variables by their upper bound + const replacedTypes = this.replaceVariablesWithUpperBound(simplifiedTypes); // Partition types by their kind const partitionedTypes = this.partitionTypesLCS(replacedTypes); @@ -1130,9 +1130,9 @@ export class SafeDsTypeComputer { } } - private replaceTypeParameterTypesWithUpperBound(simplifiedTypes: Type[]) { + private replaceVariablesWithUpperBound(simplifiedTypes: Type[]) { return simplifiedTypes.map((it) => { - if (it instanceof TypeParameterType) { + if (it instanceof TypeVariable) { return this.computeUpperBound(it); } else { return it; @@ -1454,7 +1454,7 @@ export class SafeDsTypeComputer { const substitutions: TypeParameterSubstitutions = new Map(); for (const typeParameter of typeParameters) { - substitutions.set(typeParameter, this.factory.createTypeParameterType(typeParameter, false)); + substitutions.set(typeParameter, this.factory.createTypeVariable(typeParameter, false)); } return this.factory.createClassType(declaration, substitutions, type.isExplicitlyNullable); @@ -1474,7 +1474,7 @@ export class SafeDsTypeComputer { // See where the type parameters ended up in the computed super type const invertedTypeParameterMap = new Map(); for (const [key, value] of superType.substitutions) { - if (value instanceof TypeParameterType) { + if (value instanceof TypeVariable) { invertedTypeParameterMap.set(value.declaration, key); } } @@ -1557,7 +1557,7 @@ export class SafeDsTypeComputer { * parameters on parent types get substituted. */ computeMatchingSupertype( - type: ClassType | TypeParameterType | undefined, + type: ClassType | TypeVariable | undefined, target: SdsClass | undefined, ): ClassType | undefined { // Handle undefined @@ -1566,7 +1566,7 @@ export class SafeDsTypeComputer { } // Handle type parameter types - if (type instanceof TypeParameterType) { + if (type instanceof TypeVariable) { const upperBound = this.computeUpperBound(type); if (upperBound instanceof ClassType) { return this.computeMatchingSupertype(upperBound, target); @@ -1672,10 +1672,10 @@ export class SafeDsTypeComputer { */ interface ComputeUpperBoundOptions { /** - * If `true`, the computation stops at type parameter types and returns them as is. Otherwise, it finds the bounds - * for the type parameter types recursively. + * If `true`, the computation stops at type variables and returns them as is. Otherwise, it finds the bounds for the + * type variable recursively. */ - stopAtTypeParameterType?: boolean; + stopAtTypeVariable?: boolean; } interface ComputeTypeState { diff --git a/packages/safe-ds-lang/src/language/typing/safe-ds-type-factory.ts b/packages/safe-ds-lang/src/language/typing/safe-ds-type-factory.ts index eec41eebe..cfbad512d 100644 --- a/packages/safe-ds-lang/src/language/typing/safe-ds-type-factory.ts +++ b/packages/safe-ds-lang/src/language/typing/safe-ds-type-factory.ts @@ -11,7 +11,7 @@ import { StaticType, Type, TypeParameterSubstitutions, - TypeParameterType, + TypeVariable, UnionType, } from './model.js'; import { Constant } from '../partialEvaluation/model.js'; @@ -66,8 +66,8 @@ export class SafeDsTypeFactory { return new StaticType(this.services, instanceType); } - createTypeParameterType(declaration: SdsTypeParameter, isExplicitlyNullable: boolean): TypeParameterType { - return new TypeParameterType(declaration, isExplicitlyNullable); + createTypeVariable(declaration: SdsTypeParameter, isExplicitlyNullable: boolean): TypeVariable { + return new TypeVariable(declaration, isExplicitlyNullable); } createUnionType(...types: Type[]): UnionType { diff --git a/packages/safe-ds-lang/src/language/validation/types.ts b/packages/safe-ds-lang/src/language/validation/types.ts index d67a4d988..f859a1d92 100644 --- a/packages/safe-ds-lang/src/language/validation/types.ts +++ b/packages/safe-ds-lang/src/language/validation/types.ts @@ -26,7 +26,7 @@ import { } from '../generated/ast.js'; import { getArguments, getTypeArguments, getTypeParameters, TypeParameter } from '../helpers/nodeProperties.js'; import { SafeDsServices } from '../safe-ds-module.js'; -import { ClassType, NamedTupleType, TypeParameterType, UnknownType } from '../typing/model.js'; +import { ClassType, NamedTupleType, TypeVariable, UnknownType } from '../typing/model.js'; export const CODE_TYPE_CALLABLE_RECEIVER = 'type/callable-receiver'; export const CODE_TYPE_MISMATCH = 'type/mismatch'; @@ -135,7 +135,7 @@ export const indexedAccessIndexMustHaveCorrectType = (services: SafeDsServices) code: CODE_TYPE_MISMATCH, }); } - } else if (receiverType instanceof ClassType || receiverType instanceof TypeParameterType) { + } else if (receiverType instanceof ClassType || receiverType instanceof TypeVariable) { const mapType = typeComputer.computeMatchingSupertype(receiverType, coreClasses.Map); if (mapType) { const keyType = mapType.getTypeParameterTypeByIndex(0); @@ -293,7 +293,7 @@ export const namedTypeTypeArgumentsMustMatchBounds = (services: SafeDsServices) } const upperBound = typeComputer - .computeUpperBound(typeParameter, { stopAtTypeParameterType: true }) + .computeUpperBound(typeParameter, { stopAtTypeVariable: true }) .substituteTypeParameters(type.substitutions); if (!typeChecker.isSubtypeOf(typeArgumentType, upperBound)) { @@ -400,7 +400,7 @@ export const typeParameterDefaultValueMustMatchUpperBound = (services: SafeDsSer } const defaultValueType = typeComputer.computeType(node.defaultValue); - const upperBoundType = typeComputer.computeUpperBound(node, { stopAtTypeParameterType: true }); + const upperBoundType = typeComputer.computeUpperBound(node, { stopAtTypeVariable: true }); if (!typeChecker.isSubtypeOf(defaultValueType, upperBoundType)) { accept('error', `Expected type '${upperBoundType}' but got '${defaultValueType}'.`, { diff --git a/packages/safe-ds-lang/tests/language/typing/model.test.ts b/packages/safe-ds-lang/tests/language/typing/model.test.ts index afece30f4..df0b66bf5 100644 --- a/packages/safe-ds-lang/tests/language/typing/model.test.ts +++ b/packages/safe-ds-lang/tests/language/typing/model.test.ts @@ -10,7 +10,7 @@ import { NamedTupleEntry, Type, TypeParameterSubstitutions, - TypeParameterType, + TypeVariable, UnknownType, } from '../../../src/language/typing/model.js'; import { getNodeOfType } from '../../helpers/nodeFinder.js'; @@ -107,8 +107,8 @@ describe('type model', async () => { valueOfOtherType: () => UnknownType, }, { - value: () => new TypeParameterType(typeParameter1, true), - unequalValueOfSameType: () => new TypeParameterType(typeParameter2, true), + value: () => new TypeVariable(typeParameter1, true), + unequalValueOfSameType: () => new TypeVariable(typeParameter2, true), valueOfOtherType: () => UnknownType, }, { @@ -207,11 +207,11 @@ describe('type model', async () => { expectedString: 'MyEnum1.MyEnumVariant1?', }, { - value: new TypeParameterType(typeParameter1, false), + value: new TypeVariable(typeParameter1, false), expectedString: 'K', }, { - value: new TypeParameterType(typeParameter1, true), + value: new TypeVariable(typeParameter1, true), expectedString: 'K?', }, { @@ -240,11 +240,9 @@ describe('type model', async () => { callable1, undefined, factory.createNamedTupleType( - new NamedTupleEntry(parameter1, 'p1', new TypeParameterType(typeParameter1, false)), - ), - factory.createNamedTupleType( - new NamedTupleEntry(result, 'r', new TypeParameterType(typeParameter1, false)), + new NamedTupleEntry(parameter1, 'p1', new TypeVariable(typeParameter1, false)), ), + factory.createNamedTupleType(new NamedTupleEntry(result, 'r', new TypeVariable(typeParameter1, false))), ), substitutions: substitutions1, expectedType: factory.createCallableType( @@ -265,7 +263,7 @@ describe('type model', async () => { }, { type: factory.createNamedTupleType( - new NamedTupleEntry(parameter1, 'p1', new TypeParameterType(typeParameter1, false)), + new NamedTupleEntry(parameter1, 'p1', new TypeVariable(typeParameter1, false)), ), substitutions: substitutions1, expectedType: factory.createNamedTupleType( @@ -273,11 +271,7 @@ describe('type model', async () => { ), }, { - type: new ClassType( - class1, - new Map([[typeParameter2, new TypeParameterType(typeParameter1, false)]]), - false, - ), + type: new ClassType(class1, new Map([[typeParameter2, new TypeVariable(typeParameter1, false)]]), false), substitutions: substitutions1, expectedType: new ClassType( class1, @@ -296,32 +290,32 @@ describe('type model', async () => { expectedType: new EnumVariantType(enumVariant1, false), }, { - type: new TypeParameterType(typeParameter1, false), + type: new TypeVariable(typeParameter1, false), substitutions: substitutions1, expectedType: factory.createLiteralType(new IntConstant(1n)), }, { - type: new TypeParameterType(typeParameter1, true), + type: new TypeVariable(typeParameter1, true), substitutions: substitutions1, expectedType: factory.createLiteralType(new IntConstant(1n), NullConstant), }, { - type: new TypeParameterType(typeParameter2, false), + type: new TypeVariable(typeParameter2, false), substitutions: substitutions1, - expectedType: new TypeParameterType(typeParameter2, false), + expectedType: new TypeVariable(typeParameter2, false), }, { type: factory.createStaticType( - new ClassType(class1, new Map([[typeParameter1, new TypeParameterType(typeParameter2, false)]]), false), + new ClassType(class1, new Map([[typeParameter1, new TypeVariable(typeParameter2, false)]]), false), ), substitutions: substitutions1, expectedType: factory.createStaticType( - new ClassType(class1, new Map([[typeParameter1, new TypeParameterType(typeParameter2, false)]]), false), + new ClassType(class1, new Map([[typeParameter1, new TypeVariable(typeParameter2, false)]]), false), ), }, { type: factory.createUnionType( - new ClassType(class1, new Map([[typeParameter2, new TypeParameterType(typeParameter1, false)]]), false), + new ClassType(class1, new Map([[typeParameter2, new TypeVariable(typeParameter1, false)]]), false), ), substitutions: substitutions1, expectedType: factory.createUnionType( @@ -461,14 +455,14 @@ describe('type model', async () => { expectedType: factory.createStaticType(new ClassType(class1, new Map(), false)), }, { - type: new TypeParameterType(typeParameter1, false), + type: new TypeVariable(typeParameter1, false), isNullable: true, - expectedType: new TypeParameterType(typeParameter1, true), + expectedType: new TypeVariable(typeParameter1, true), }, { - type: new TypeParameterType(typeParameter1, true), + type: new TypeVariable(typeParameter1, true), isNullable: false, - expectedType: new TypeParameterType(typeParameter1, false), + expectedType: new TypeVariable(typeParameter1, false), }, { type: factory.createUnionType(), diff --git a/packages/safe-ds-lang/tests/language/typing/type checker/isSubOrSupertypeOf.test.ts b/packages/safe-ds-lang/tests/language/typing/type checker/isSubOrSupertypeOf.test.ts index 4c4b56921..c37209f0c 100644 --- a/packages/safe-ds-lang/tests/language/typing/type checker/isSubOrSupertypeOf.test.ts +++ b/packages/safe-ds-lang/tests/language/typing/type checker/isSubOrSupertypeOf.test.ts @@ -1028,7 +1028,7 @@ const classTypesWithTypeParameters = async (): Promise ]; }; -const typeParameterTypes = async (): Promise => { +const typeVariables = async (): Promise => { const code = ` class TestClass< Unbounded, @@ -1227,7 +1227,7 @@ const typeParameterTypes = async (): Promise => { }; describe('SafeDsTypeChecker', async () => { - const testCases = (await Promise.all([basic(), classTypesWithTypeParameters(), typeParameterTypes()])).flat(); + const testCases = (await Promise.all([basic(), classTypesWithTypeParameters(), typeVariables()])).flat(); describe.each(testCases)('isSubtypeOf', ({ type1, type2, expected }) => { it(`should check whether ${type1} a subtype of ${type2}`, () => { diff --git a/packages/safe-ds-lang/tests/resources/typing/highest common subtype/class type and type parameter type/main.sdsdev b/packages/safe-ds-lang/tests/resources/typing/highest common subtype/class type and type variable/main.sdsdev similarity index 95% rename from packages/safe-ds-lang/tests/resources/typing/highest common subtype/class type and type parameter type/main.sdsdev rename to packages/safe-ds-lang/tests/resources/typing/highest common subtype/class type and type variable/main.sdsdev index 9586a80c7..c85254098 100644 --- a/packages/safe-ds-lang/tests/resources/typing/highest common subtype/class type and type parameter type/main.sdsdev +++ b/packages/safe-ds-lang/tests/resources/typing/highest common subtype/class type and type variable/main.sdsdev @@ -1,4 +1,4 @@ -package tests.typing.highestCommonSubtype.classTypeAndTypeParameterType +package tests.typing.highestCommonSubtype.classTypeAndTypeVariable class Contravariant diff --git a/packages/safe-ds-lang/tests/resources/typing/highest common subtype/enum type and type parameter type/main.sdsdev b/packages/safe-ds-lang/tests/resources/typing/highest common subtype/enum type and type variable/main.sdsdev similarity index 95% rename from packages/safe-ds-lang/tests/resources/typing/highest common subtype/enum type and type parameter type/main.sdsdev rename to packages/safe-ds-lang/tests/resources/typing/highest common subtype/enum type and type variable/main.sdsdev index 852368bfe..93e1b82cd 100644 --- a/packages/safe-ds-lang/tests/resources/typing/highest common subtype/enum type and type parameter type/main.sdsdev +++ b/packages/safe-ds-lang/tests/resources/typing/highest common subtype/enum type and type variable/main.sdsdev @@ -1,4 +1,4 @@ -package tests.typing.highestCommonSubtype.enumTypeAndTypeParameterType +package tests.typing.highestCommonSubtype.enumTypeAndTypeVariable class Contravariant diff --git a/packages/safe-ds-lang/tests/resources/typing/highest common subtype/enum variant type and type parameter type/main.sdsdev b/packages/safe-ds-lang/tests/resources/typing/highest common subtype/enum variant type and type variable/main.sdsdev similarity index 99% rename from packages/safe-ds-lang/tests/resources/typing/highest common subtype/enum variant type and type parameter type/main.sdsdev rename to packages/safe-ds-lang/tests/resources/typing/highest common subtype/enum variant type and type variable/main.sdsdev index 82b1ef21b..70bef2122 100644 --- a/packages/safe-ds-lang/tests/resources/typing/highest common subtype/enum variant type and type parameter type/main.sdsdev +++ b/packages/safe-ds-lang/tests/resources/typing/highest common subtype/enum variant type and type variable/main.sdsdev @@ -1,4 +1,4 @@ -package tests.typing.highestCommonSubtype.enumVariantTypeAndTypeParameterType +package tests.typing.highestCommonSubtype.enumVariantTypeAndTypeVariable class Contravariant diff --git a/packages/safe-ds-lang/tests/resources/typing/highest common subtype/type parameter type and type parameter type/main.sdsdev b/packages/safe-ds-lang/tests/resources/typing/highest common subtype/type variable and type variable/main.sdsdev similarity index 90% rename from packages/safe-ds-lang/tests/resources/typing/highest common subtype/type parameter type and type parameter type/main.sdsdev rename to packages/safe-ds-lang/tests/resources/typing/highest common subtype/type variable and type variable/main.sdsdev index 829c20a91..aba7ba7eb 100644 --- a/packages/safe-ds-lang/tests/resources/typing/highest common subtype/type parameter type and type parameter type/main.sdsdev +++ b/packages/safe-ds-lang/tests/resources/typing/highest common subtype/type variable and type variable/main.sdsdev @@ -1,4 +1,4 @@ -package tests.typing.highestCommonSubtype.typeParameterTypeAndTypeParameterType +package tests.typing.highestCommonSubtype.typeVariableAndTypeVariable class Contravariant diff --git a/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/class type and type parameter type/main.sdsdev b/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/class type and type variable/main.sdsdev similarity index 89% rename from packages/safe-ds-lang/tests/resources/typing/lowest common supertype/class type and type parameter type/main.sdsdev rename to packages/safe-ds-lang/tests/resources/typing/lowest common supertype/class type and type variable/main.sdsdev index 6b68b8290..823bf0d85 100644 --- a/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/class type and type parameter type/main.sdsdev +++ b/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/class type and type variable/main.sdsdev @@ -1,4 +1,4 @@ -package tests.typing.lowestCommonSupertype.classTypeAndTypeParameterType +package tests.typing.lowestCommonSupertype.classTypeAndTypeVariable class C class D diff --git a/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/enum type and type parameter type/main.sdsdev b/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/enum type and type variable/main.sdsdev similarity index 92% rename from packages/safe-ds-lang/tests/resources/typing/lowest common supertype/enum type and type parameter type/main.sdsdev rename to packages/safe-ds-lang/tests/resources/typing/lowest common supertype/enum type and type variable/main.sdsdev index 14568f31e..f8b2aa139 100644 --- a/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/enum type and type parameter type/main.sdsdev +++ b/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/enum type and type variable/main.sdsdev @@ -1,4 +1,4 @@ -package tests.typing.lowestCommonSupertype.enumTypeAndTypeParameterType +package tests.typing.lowestCommonSupertype.enumTypeAndTypeVariable enum E { V diff --git a/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/enum variant type and type parameter type/main.sdsdev b/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/enum variant type and type variable/main.sdsdev similarity index 98% rename from packages/safe-ds-lang/tests/resources/typing/lowest common supertype/enum variant type and type parameter type/main.sdsdev rename to packages/safe-ds-lang/tests/resources/typing/lowest common supertype/enum variant type and type variable/main.sdsdev index 45eeb4321..644fc14df 100644 --- a/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/enum variant type and type parameter type/main.sdsdev +++ b/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/enum variant type and type variable/main.sdsdev @@ -1,4 +1,4 @@ -package tests.typing.lowestCommonSupertype.enumVariantTypeAndTypeParameterType +package tests.typing.lowestCommonSupertype.enumVariantTypeAndTypeVariable enum E { V1 diff --git a/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/literal type and type parameter type/main.sdsdev b/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/literal type and type variable/main.sdsdev similarity index 90% rename from packages/safe-ds-lang/tests/resources/typing/lowest common supertype/literal type and type parameter type/main.sdsdev rename to packages/safe-ds-lang/tests/resources/typing/lowest common supertype/literal type and type variable/main.sdsdev index 59380141c..72043978e 100644 --- a/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/literal type and type parameter type/main.sdsdev +++ b/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/literal type and type variable/main.sdsdev @@ -1,4 +1,4 @@ -package tests.typing.lowestCommonSupertype.literalTypeAndTypeParameterType +package tests.typing.lowestCommonSupertype.literalTypeAndTypeVariable class Test< Unbounded, diff --git a/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/type parameter type and type parameter type/main.sdsdev b/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/type variable and type variable/main.sdsdev similarity index 93% rename from packages/safe-ds-lang/tests/resources/typing/lowest common supertype/type parameter type and type parameter type/main.sdsdev rename to packages/safe-ds-lang/tests/resources/typing/lowest common supertype/type variable and type variable/main.sdsdev index 7a1d97b65..3033991bb 100644 --- a/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/type parameter type and type parameter type/main.sdsdev +++ b/packages/safe-ds-lang/tests/resources/typing/lowest common supertype/type variable and type variable/main.sdsdev @@ -1,4 +1,4 @@ -package tests.typing.lowestCommonSupertype.typeParameterTypeAndTypeParameterType +package tests.typing.lowestCommonSupertype.typeVariableAndTypeVariable class C class D sub C