diff --git a/langkit/templates/properties/domain_ada.mako b/langkit/templates/properties/domain_ada.mako index 4ffc5fdff..9849bf372 100644 --- a/langkit/templates/properties/domain_ada.mako +++ b/langkit/templates/properties/domain_ada.mako @@ -15,7 +15,9 @@ begin if element_type.is_entity_type else element_type) node_expr = 'Item.Node' if element_type.is_entity_type else 'Item' - info_expr = 'Item.Info' if element_type.is_entity_type else '<>' + info_expr = ('Item.Info' + if element_type.is_entity_type else + 'No_Entity_Info') %> Item : constant ${element_type.name} := Get (Self, Dom, J); begin diff --git a/testsuite/tests/properties/domain_node/expected_concrete_syntax.lkt b/testsuite/tests/properties/domain_node/expected_concrete_syntax.lkt new file mode 100644 index 000000000..0757aeed5 --- /dev/null +++ b/testsuite/tests/properties/domain_node/expected_concrete_syntax.lkt @@ -0,0 +1,20 @@ +import lexer_example + +@with_lexer(foo_lexer) +grammar foo_grammar { + @main_rule main_rule <- Example("example") +} + +@abstract +class FooNode implements Node[FooNode] { + v: LogicVar +} + +class Example: FooNode { + fun identity(): Entity[Example] = self + + @exported + fun test(): Bool = ( + %domain(node.v, [node]) and %eq(node.v, node.v, conv_prop=Example.identity) + ).solve() +} diff --git a/testsuite/tests/properties/domain_node/main.adb b/testsuite/tests/properties/domain_node/main.adb new file mode 100644 index 000000000..401086e53 --- /dev/null +++ b/testsuite/tests/properties/domain_node/main.adb @@ -0,0 +1,19 @@ +with Ada.Text_IO; use Ada.Text_IO; + +with Libfoolang.Analysis; use Libfoolang.Analysis; + +procedure Main is + Ctx : constant Analysis_Context := Create_Context; + U : constant Analysis_Unit := Ctx.Get_From_Buffer + (Filename => "main.txt", Buffer => "example"); + + Node : constant Example := U.Root.As_Example; + Dummy : Boolean; +begin + if U.Has_Diagnostics then + Put_Line ("Parsing errors..."); + return; + end if; + Dummy := Node.P_Test; + Put_Line ("main.adb: Done."); +end Main; diff --git a/testsuite/tests/properties/domain_node/test.out b/testsuite/tests/properties/domain_node/test.out new file mode 100644 index 000000000..4c850d9bd --- /dev/null +++ b/testsuite/tests/properties/domain_node/test.out @@ -0,0 +1,2 @@ +main.adb: Done. +Done diff --git a/testsuite/tests/properties/domain_node/test.py b/testsuite/tests/properties/domain_node/test.py new file mode 100644 index 000000000..22baf9bfb --- /dev/null +++ b/testsuite/tests/properties/domain_node/test.py @@ -0,0 +1,32 @@ +""" +Test that using the ``domain`` DSL construct with bare nodes does not set +uninitialized data into the corresponding logic variable. +""" + +from langkit.dsl import ASTNode, T, UserField +from langkit.expressions import Bind, Entity, Self, langkit_property + +from utils import build_and_run + + +class FooNode(ASTNode): + v = UserField(type=T.LogicVar, public=False) + + +class Example(FooNode): + @langkit_property(return_type=T.Example.entity) + def identity(): + return Entity + + @langkit_property(public=True) + def test(): + return (Self.v.domain([Self]) & + Bind(Self.v, Self.v, conv_prop=Example.identity)).solve + + +build_and_run( + lkt_file='expected_concrete_syntax.lkt', + gpr_mains=['main.adb'], + types_from_lkt=True, +) +print('Done') diff --git a/testsuite/tests/properties/domain_node/test.yaml b/testsuite/tests/properties/domain_node/test.yaml new file mode 100644 index 000000000..30423a038 --- /dev/null +++ b/testsuite/tests/properties/domain_node/test.yaml @@ -0,0 +1 @@ +driver: python