Skip to content

Commit c68098d

Browse files
committed
Lkt lowering: handle cast expressions
TN: RA22-015
1 parent 4384876 commit c68098d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

langkit/lkt_lowering.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
)
2727
import langkit.expressions as E
2828
from langkit.expressions import (
29-
AbstractExpression, AbstractProperty, AbstractVariable, Property,
29+
AbstractExpression, AbstractProperty, AbstractVariable, Cast, Property,
3030
PropertyDef
3131
)
3232
from langkit.lexer import (
@@ -1602,6 +1602,14 @@ def lower_args() -> Tuple[List[AbstractExpression],
16021602
]
16031603
return E.IsA(subexpr, *nodes)
16041604

1605+
elif isinstance(expr, L.CastExpr):
1606+
subexpr = lower(expr.f_expr)
1607+
excludes_null = expr.f_excludes_null.p_as_bool
1608+
dest_type = self.resolve_type_decl(
1609+
expr.f_dest_type.p_designated_type
1610+
)
1611+
return Cast(subexpr, dest_type, do_raise=excludes_null)
1612+
16051613
elif isinstance(expr, L.NotExpr):
16061614
return E.Not(lower(expr.f_expr))
16071615

testsuite/tests/properties/analysis_unit/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ class Plus(Expression):
4343

4444

4545
build_and_run(lkt_file='expected_concrete_syntax.lkt', py_script='main.py',
46-
lkt_semantic_checks=True)
46+
types_from_lkt=True)
4747
print('Done')

0 commit comments

Comments
 (0)