Skip to content

Commit

Permalink
fix: Python generation for type casts (#1000)
Browse files Browse the repository at this point in the history
### Summary of Changes

Previously, the Python generator threw an error, since type casts were
not handled. Now, they are handled properly.
  • Loading branch information
lars-reimann authored Apr 6, 2024
1 parent 8d22e67 commit 621ab86
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
isSdsTemplateStringInner,
isSdsTemplateStringPart,
isSdsTemplateStringStart,
isSdsTypeCast,
isSdsWildcard,
isSdsYield,
SdsArgument,
Expand Down Expand Up @@ -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}`);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Segments ---------------------------------------------------------------------

def mySegment(p):
a = p

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package tests.generation.expressions.typeCasts

segment mySegment(p: Int) {
val a = p as Int;
}

0 comments on commit 621ab86

Please sign in to comment.