Skip to content

Commit

Permalink
Fix generation for functions with builtin types
Browse files Browse the repository at this point in the history
Ref. #752
  • Loading branch information
kanigsson committed Aug 26, 2021
1 parent 268f271 commit 73b2236
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
14 changes: 9 additions & 5 deletions rflx/generator/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
While,
WithClause,
)
from rflx.const import BUILTINS_PACKAGE, INTERNAL_PACKAGE
from rflx.error import Subsystem, fail, fatal_fail
from rflx.model.type_ import is_builtin_type, is_internal_type

from . import const

Expand Down Expand Up @@ -304,7 +304,7 @@ def _create_function_parameters(
[ID(function.identifier)],
ID(self._prefix * function.return_type * "Structure")
if isinstance(function.type_, rty.Message)
else ID(self._prefix * function.return_type),
else ID(function.return_type),
)
)

Expand All @@ -324,7 +324,7 @@ def _create_function_parameters(
if a.type_ == rty.OPAQUE
else ID(self._prefix * a.type_identifier * "Structure")
if isinstance(a.type_, rty.Message)
else ID(self._prefix * a.type_identifier),
else ID(a.type_identifier),
)
)

Expand Down Expand Up @@ -354,7 +354,9 @@ def _create_context(self) -> Tuple[List[ContextItem], List[ContextItem]]:
(self._session_context.referenced_types_body, body_context),
]:
for type_identifier in referenced_types:
if type_identifier.parent in [INTERNAL_PACKAGE, BUILTINS_PACKAGE]:
if model.type_.is_internal_type(type_identifier) or model.type_.is_builtin_type(
type_identifier
):
continue
type_ = self._model_type(type_identifier)
context.extend(
Expand All @@ -378,7 +380,9 @@ def _create_context(self) -> Tuple[List[ContextItem], List[ContextItem]]:
)

for type_identifier in self._session_context.used_types_body:
if type_identifier.parent in [INTERNAL_PACKAGE, BUILTINS_PACKAGE]:
if is_builtin_type(type_identifier) or is_internal_type(type_identifier):
# ISSUE: nedbat/coveragepy#772
dummy = 0 # noqa: F841
continue
if type_identifier in [const.TYPES_LENGTH, const.TYPES_INDEX, const.TYPES_BIT_LENGTH]:
body_context.append(
Expand Down
29 changes: 29 additions & 0 deletions tests/integration/specification_model_generator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,32 @@ def test_message_expression_value_outside_type_range(tmp_path: Path) -> None:
end Test;
"""
utils.assert_compilable_code_string(spec, tmp_path)


def test_builtin_type_return_type_of_function(tmp_path: Path) -> None:
spec = """
package Empty_Ident is
type My_Int is mod 2 ** 8;
generic
with function Output (X : My_Int) return Boolean;
session Session with
Initial => First,
Final => Last
is
X : My_Int;
Z : Boolean;
begin
state First is
begin
X := 1;
Z := Output (X);
transition
then Last
end First;
state Last is null state;
end Session;
end Empty_Ident;
"""
utils.assert_compilable_code_string(spec, tmp_path)

0 comments on commit 73b2236

Please sign in to comment.