diff --git a/.mega-linter.yml b/.mega-linter.yml index 4595cba51..b0b5ddb30 100644 --- a/.mega-linter.yml +++ b/.mega-linter.yml @@ -21,4 +21,4 @@ TSX_ESLINT_FILE_EXTENSIONS: # Commands PRE_COMMANDS: - - command: npm i @lars-reimann/eslint-config-svelte eslint-plugin-vitest @lars-reimann/prettier-config-svelte + - command: npm i @lars-reimann/eslint-config-svelte eslint-plugin-vitest@0.4.0 @lars-reimann/prettier-config-svelte diff --git a/packages/safe-ds-lang/src/language/generation/safe-ds-python-generator.ts b/packages/safe-ds-lang/src/language/generation/safe-ds-python-generator.ts index fb4508c7e..e775ed899 100644 --- a/packages/safe-ds-lang/src/language/generation/safe-ds-python-generator.ts +++ b/packages/safe-ds-lang/src/language/generation/safe-ds-python-generator.ts @@ -47,6 +47,7 @@ import { isSdsTemplateStringInner, isSdsTemplateStringPart, isSdsTemplateStringStart, + isSdsTypeCast, isSdsWildcard, isSdsYield, SdsArgument, @@ -907,6 +908,8 @@ export class SafeDsPythonGenerator { const referenceImport = this.createImportDataForReference(expression); frame.addImport(referenceImport); return traceToNode(expression)(referenceImport?.alias ?? this.getPythonNameOrDefault(declaration)); + } else if (isSdsTypeCast(expression)) { + return traceToNode(expression)(this.generateExpression(expression.expression, frame)); } /* c8 ignore next 2 */ throw new Error(`Unknown expression type: ${expression.$type}`); diff --git a/packages/safe-ds-lang/tests/resources/generation/python/expressions/type casts/generated/tests/generation/expressions/typeCasts/gen_input.py b/packages/safe-ds-lang/tests/resources/generation/python/expressions/type casts/generated/tests/generation/expressions/typeCasts/gen_input.py new file mode 100644 index 000000000..e3ecd097a --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/generation/python/expressions/type casts/generated/tests/generation/expressions/typeCasts/gen_input.py @@ -0,0 +1,4 @@ +# Segments --------------------------------------------------------------------- + +def mySegment(p): + a = p diff --git a/packages/safe-ds-lang/tests/resources/generation/python/expressions/type casts/generated/tests/generation/expressions/typeCasts/gen_input.py.map b/packages/safe-ds-lang/tests/resources/generation/python/expressions/type casts/generated/tests/generation/expressions/typeCasts/gen_input.py.map new file mode 100644 index 000000000..360c197c0 --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/generation/python/expressions/type casts/generated/tests/generation/expressions/typeCasts/gen_input.py.map @@ -0,0 +1 @@ +{"version":3,"sources":["input.sdstest"],"names":["mysegment","p"],"mappings":"AAAA;;AAEA,IAAQA,SAAS,CAACC,CAAC;IACf,IAAQA,CAAC","file":"gen_input.py"} \ No newline at end of file diff --git a/packages/safe-ds-lang/tests/resources/generation/python/expressions/type casts/input.sdstest b/packages/safe-ds-lang/tests/resources/generation/python/expressions/type casts/input.sdstest new file mode 100644 index 000000000..a264cede4 --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/generation/python/expressions/type casts/input.sdstest @@ -0,0 +1,5 @@ +package tests.generation.expressions.typeCasts + +segment mySegment(p: Int) { + val a = p as Int; +}