diff --git a/aas_core_codegen/intermediate/_translate.py b/aas_core_codegen/intermediate/_translate.py index 604229401..311e7589a 100644 --- a/aas_core_codegen/intermediate/_translate.py +++ b/aas_core_codegen/intermediate/_translate.py @@ -4456,9 +4456,12 @@ def _verify_only_simple_type_patterns(symbol_table: SymbolTable) -> List[Error]: type_anno = beneath_optional(prop.type_annotation) if isinstance(type_anno, ListTypeAnnotation): if not ( - isinstance(type_anno.items, OurTypeAnnotation) - and isinstance( - type_anno.items.our_type, (AbstractClass, ConcreteClass) + isinstance(type_anno.items, PrimitiveTypeAnnotation) + or ( + isinstance(type_anno.items, OurTypeAnnotation) + and isinstance( + type_anno.items.our_type, (AbstractClass, ConcreteClass) + ) ) ): errors.append( @@ -4466,7 +4469,7 @@ def _verify_only_simple_type_patterns(symbol_table: SymbolTable) -> List[Error]: prop.parsed.node, f"We currently support only a limited set of " f"type annotation patterns. At the moment, we handle " - f"only lists of classes (both concrete or abstract), " + f"only lists of classes (both concrete or abstract) or primitive types, " f"but the property {prop.name!r} " f"of the class {cls.name!r} " f"has type: {prop.type_annotation}. " diff --git a/test_data/intermediate/expected/type_annotation/subscripted/expected_symbol_table.txt b/test_data/intermediate/expected/type_annotation/subscripted/class/expected_symbol_table.txt similarity index 100% rename from test_data/intermediate/expected/type_annotation/subscripted/expected_symbol_table.txt rename to test_data/intermediate/expected/type_annotation/subscripted/class/expected_symbol_table.txt diff --git a/test_data/intermediate/expected/type_annotation/subscripted/meta_model.py b/test_data/intermediate/expected/type_annotation/subscripted/class/meta_model.py similarity index 100% rename from test_data/intermediate/expected/type_annotation/subscripted/meta_model.py rename to test_data/intermediate/expected/type_annotation/subscripted/class/meta_model.py diff --git a/test_data/intermediate/expected/type_annotation/subscripted/primitive/expected_symbol_table.txt b/test_data/intermediate/expected/type_annotation/subscripted/primitive/expected_symbol_table.txt new file mode 100644 index 000000000..409ed86fb --- /dev/null +++ b/test_data/intermediate/expected/type_annotation/subscripted/primitive/expected_symbol_table.txt @@ -0,0 +1,85 @@ +SymbolTable( + our_types=[ + ConcreteClass( + name='SomeContainerClass', + inheritances=[], + inheritance_id_set=..., + ancestors=[], + ancestor_id_set=..., + is_implementation_specific=False, + interface=None, + descendant_id_set=..., + descendants=[], + concrete_descendant_id_set=..., + concrete_descendants=[], + properties=[ + Property( + name='x', + type_annotation=ListTypeAnnotation( + items=PrimitiveTypeAnnotation( + a_type='STR', + parsed=...), + parsed=...), + description=None, + specified_for='Reference to ConcreteClass SomeContainerClass', + parsed=...)], + methods=[], + constructor=Constructor( + name='__init__', + arguments=[ + Argument( + name='x', + type_annotation=ListTypeAnnotation( + items=PrimitiveTypeAnnotation( + a_type='STR', + parsed=...), + parsed=...), + default=None, + parsed=...)], + returns=None, + description=None, + contracts=Contracts( + preconditions=[], + snapshots=[], + postconditions=[]), + parsed=..., + arguments_by_name=..., + is_implementation_specific=False, + statements=[ + textwrap.dedent("""\ + AssignArgument( + name='x', + argument='x', + default=None)""")], + inlined_statements=[ + textwrap.dedent("""\ + AssignArgument( + name='x', + argument='x', + default=None)""")]), + invariants=[], + serialization=Serialization( + with_model_type=False), + description=None, + parsed=..., + properties_by_name=..., + property_id_set=..., + methods_by_name=..., + method_id_set=..., + invariant_id_set=...)], + our_types_topologically_sorted=[ + 'Reference to our type SomeContainerClass'], + enumerations=[], + constrained_primitives=[], + classes=[ + 'Reference to our type SomeContainerClass'], + concrete_classes=[ + 'Reference to our type SomeContainerClass'], + constants=[], + constants_by_name=..., + verification_functions=[], + verification_functions_by_name=..., + meta_model=MetaModel( + description=None, + version='dummy', + xml_namespace='https://dummy.com')) \ No newline at end of file diff --git a/test_data/intermediate/expected/type_annotation/subscripted/primitive/meta_model.py b/test_data/intermediate/expected/type_annotation/subscripted/primitive/meta_model.py new file mode 100644 index 000000000..345a02a6c --- /dev/null +++ b/test_data/intermediate/expected/type_annotation/subscripted/primitive/meta_model.py @@ -0,0 +1,9 @@ +class SomeContainerClass: + x: List[str] + + def __init__(self, x: List[str]) -> None: + self.x = x + + +__version__ = "dummy" +__xml_namespace__ = "https://dummy.com" diff --git a/test_data/intermediate/unexpected/properties_and_constructor_arguments_do_not_match/type_missmatch/expected_error.txt b/test_data/intermediate/unexpected/properties_and_constructor_arguments_do_not_match/type_missmatch/expected_error.txt new file mode 100644 index 000000000..14db0c0d5 --- /dev/null +++ b/test_data/intermediate/unexpected/properties_and_constructor_arguments_do_not_match/type_missmatch/expected_error.txt @@ -0,0 +1 @@ +The constructor argument 'x' and the property 'x' for the class 'SomeContainerClass' mismatch in type. The argument is typed as List[int] while the property is typed as List[str]. We expect the constructors and the properties to match in type. \ No newline at end of file diff --git a/test_data/intermediate/unexpected/properties_and_constructor_arguments_do_not_match/type_missmatch/meta_model.py b/test_data/intermediate/unexpected/properties_and_constructor_arguments_do_not_match/type_missmatch/meta_model.py new file mode 100644 index 000000000..f3c3efa79 --- /dev/null +++ b/test_data/intermediate/unexpected/properties_and_constructor_arguments_do_not_match/type_missmatch/meta_model.py @@ -0,0 +1,9 @@ +class SomeContainerClass: + x: List[str] + + def __init__(self, x: List[int]) -> None: + self.x = x + + +__version__ = "dummy" +__xml_namespace__ = "https://dummy.com"