Skip to content

Make read-only sequences of verifications generic - #852

Merged
mristin merged 1 commit into
mainfrom
mristin/Make-read-only-sequences-generic
Oct 15, 2026
Merged

mristin merged 1 commit into
mainfrom
mristin/Make-read-only-sequences-generic

Conversation

@mristin

@mristin mristin commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

We make the read-only Sequence[...] arguments of the verification functions generic if their items are instances of a class with descendants. This way, the sequences of the descendants can be passed without a copy, as aas-core-meta V3.2 does, e.g., in ID_shorts_are_unique(self.submodel_elements).

Go declares a type parameter, e.g., func IDShortsAreUnique[ ReferablesT ourtypes.IReferable](referables []ReferablesT), C++ a template defined in the header, C# the covariant IReadOnlyList<T>, and Java the wildcard List<? extends T>. Python and TypeScript accept the sequences of the descendants already.

The methods stay invariant, since Go methods can not have type parameters and C++ virtual methods can not be templates, and so do the mutable List[...] arguments. The type inference now checks the items of all the list arguments, and restricts the usages of the generic sequences, e.g., they can not be passed to a method.

We support in on the generic sequences with the new ourcommon.SliceContainsInstance in Go, and the immutable aliases, e.g., alias: Final[Sequence[Item]] = items, which C# and Java now declare with var.

We test all this in the new common meta-model
variance_of_containers.

We make the read-only ``Sequence[...]`` arguments of the verification
functions generic if their items are instances of a class with
descendants. This way, the sequences of the descendants can be passed
without a copy, as aas-core-meta V3.2 does, *e.g.*, in
``ID_shorts_are_unique(self.submodel_elements)``.

Go declares a type parameter, *e.g.*, ``func IDShortsAreUnique[
ReferablesT ourtypes.IReferable](referables []ReferablesT)``, C++
a template defined in the header, C# the covariant
``IReadOnlyList<T>``, and Java the wildcard ``List<? extends T>``.
Python and TypeScript accept the sequences of the descendants already.

The methods stay invariant, since Go methods can not have type
parameters and C++ virtual methods can not be templates, and so do
the mutable ``List[...]`` arguments. The type inference now checks
the items of all the list arguments, and restricts the usages of
the generic sequences, *e.g.*, they can not be passed to a method.

We support ``in`` on the generic sequences with the new
``ourcommon.SliceContainsInstance`` in Go, and the immutable aliases,
*e.g.*, ``alias: Final[Sequence[Item]] = items``, which C# and Java
now declare with ``var``.

We test all this in the new common meta-model
``variance_of_containers``.
@mristin
mristin merged commit a27ed72 into main Oct 15, 2026
5 checks passed
@mristin
mristin deleted the mristin/Make-read-only-sequences-generic branch October 15, 2026 22:02
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 38812987249

Coverage increased (+0.04%) to 90.188%

Details

  • Coverage increased (+0.04%) from the base build.
  • Patch coverage: Could not be determined — this PR's diff is too large for GitHub to return (406 error at GitHub).
  • 690 coverage regressions across 10 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

690 previously-covered lines in 10 files lost coverage.

File Lines Losing Coverage Coverage
aas_core_codegen/cpp/transpilation.py 188 82.35%
aas_core_codegen/intermediate/type_inference.py 162 90.85%
aas_core_codegen/golang/transpilation.py 156 83.72%
aas_core_codegen/golang/lib/_generate_verification.py 39 92.57%
aas_core_codegen/java/transpilation.py 35 83.68%
aas_core_codegen/cpp/lib/_generate_verification.py 30 95.16%
aas_core_codegen/csharp/transpilation.py 30 83.28%
aas_core_codegen/csharp/lib/_generate_verification.py 24 92.25%
aas_core_codegen/java/lib/_generate_verification.py 23 92.06%
aas_core_codegen/intermediate/_types.py 3 95.23%

Coverage Stats

Coverage Status
Relevant Lines: 50905
Covered Lines: 45910
Line Coverage: 90.19%
Coverage Strength: 2.71 hits per line

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants