Skip to content

Coercion of complex literals #3472

@hatyo

Description

@hatyo

It should be possible to coerce multiple complex types to find a common maximum type they can all be instances of (with / without promotion), this can get complicated considering the absence of an attribute of a complex type is permissible when the value is null.

For example, assume the user defines an array of complex literals like the following:

[ {X = 42, Y = 5.0, Z = 'bla'}, {X = 50.0, Y = 4.3}, {W = 'a'} ]

The maximum type that all of the above instances can be mapped to requires visiting all of the instances to figure that out.

Struct <> {
   X float;
   Y float;
   Z string;
   W string;
}

we could do this by calculating the maximum type via:

static Type maximumType(@Nonnull final Type t1, @Nonnull final Type t2) {

maximumType(
    maximumType(
          ToCascadesType("{X = 42, Y = 5.0, Z = 'bla'}"),
          ToCascadesType("{X = 50.0, Y = 4.3}"),
     ToCascadesType("{W = 'a'}"))

But this requires adding the capability of calculating the maximum type of a structured type to Type.maximumType which we do not have at the moment.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions