StanfordSpezi / Spezi

Open-source framework for rapid development of modern, interoperable digital health applications.
https://swiftpackageindex.com/StanfordSpezi/Spezi/documentation
MIT License
130 stars 10 forks source link

Type-safe Validation of Standard Constraints #77

Open PSchmiedmayer opened 11 months ago

PSchmiedmayer commented 11 months ago

Problem

Currently, there is no compile-time validation of the enforcement of constraints to the Standard in the configuration. E.g., the following code would compile even though the ExampleStandard does not conform to ExampleConstraint:

protocol ExampleConstraint: Standard {
    // ...
}

class ExampleComponent: Component {
    @StandardActor var standard: any ExampleConstraint

    // ...
}

actor ExampleStandard: Standard {
    // ...
}

var configuration: Configuration {
    Configuration(standard: ExampleStandard()) {
        ExampleComponent()
        // ...
    }
}

Solution

The compiler should emit a warning that the ExampleStandard does not conform to ExampleConstraint when defining it in the Configuration.

Unfortunately, this doesn't seem to be easily achievable in Swift and needs some further investigation.

Additional context

No response

Code of Conduct