CMakePP / CMakePPLang

Object-oriented extension to the CMake language.
http://cmakepp.github.io/CMakePPLang/
Apache License 2.0
11 stars 4 forks source link

Clarify how the type system handles null / empty values #111

Open AutonomicPerfectionist opened 1 year ago

AutonomicPerfectionist commented 1 year ago

Is your feature request related to a problem? Please describe. In the documentation, I am unable to find any information on how null or empty values are treated. In my mind, with experience in other languages, I would assume that an empty value would be implicitly convertible to any object type, but not to "primitive" types like ints or booleans. However, since CMake fundamentally lacks such a distinction, it's unclear what types are allowed to be "null" / empty, and what are not. The current implementation appears to treat null values as desc, which on the surface seems fine, but it makes selecting the types for parameters that might be empty difficult.

Describe the solution you'd like In newer languages, types are non-nullable by default, but have a variant type that allows null. This variant type is usually denoted by a ? character following the type. So if we have a non-null class type, we would also have a nullable class? type.

Since CMake does not have a true concept of null, and we want to allow an empty string to be used as a desc, then we would have to make desc and desc? be equivalent.

Describe alternatives you've considered Another alternative would be to simply allow an empty value to be implicitly convertible to any type, effectively making all types nullable. This has the disadvantage of looser type checking, especially since undefined variables simply resolve to an empty string

Additional context Discovered while adding cpp_assert_signature checks to CMakeTest code, since many of the asserts must allow empty values or values of a specific type