Skip to content

datatable: Replace wildcard type with its upper bound #829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 14, 2019

Conversation

mpkorstanje
Copy link
Contributor

@mpkorstanje mpkorstanje commented Dec 12, 2019

Summary

When registering steps in Kotlin using Kotlin collections as an argument e.g:

@Given("orders with an order item and the following attributes:")
fun statusFilterOrdersInEs(attributes: Map<String, Map<String, String>>)

This argument is translated to Java type as

Map<java.lang.String, ? extends java.util.Map<java.lang.String, java.lang.String>>

To handle this gracefully the simplified type system used by DataTable
should understand upper bounds. We do this by replacing the wild card type
with its upper bound.

We can assume this is safe because when registering a transformer to
type ? extends SomeType the transformer is guaranteed to produce an
object that is an instance of SomeType.

When transforming a data table to ? extends SomeType a transformer that
produces SomeType is sufficient.

This will result in ambiguity between a transformers for SomeType and
transformers for ``? extends SomeType` but that seems reasonable and might be
resolved by using a more specific producer.

Motivation and Context

cucumber/cucumber-jvm#1838

Types of changes

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).

When registering steps in Kotlin using Kotlin collections as an argument e.g:

```kotlin
@given("orders with an order item and the following attributes:")
fun statusFilterOrdersInEs(attributes: Map<String, Map<String, String>>)
```

This argument is translated to Java type as

```java
Map<java.lang.String, ? extends java.util.Map<java.lang.String, java.lang.String>>
```

To handle this gracefully the simplified type system used by `DataTable`
should understand upper bounds. We do this by replacing the wild card type
with its upper bound.

We can assume this is safe because when registering a transformer to
`type ? extends SomeType` the transformer is guaranteed to produce an
object that is an instance of `SomeType`.

When transforming a data table to ``? extends SomeType` a transformer that
produces `SomeType` is sufficient.

This will result in ambiguity between a transformers for `SomeType` and
transformers for ``? extends SomeType` but that seems reasonable and might be
resolved by using a more specific producer.
@mpkorstanje mpkorstanje force-pushed the erases-wildcard-upper-bound branch from 915b2a7 to 7fa8370 Compare December 13, 2019 19:22
@mpkorstanje mpkorstanje merged commit d85e53a into master Dec 14, 2019
@mpkorstanje mpkorstanje deleted the erases-wildcard-upper-bound branch December 14, 2019 00:09
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.

1 participant