Change the way we infer the types of steps arguments #206
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR significantly changes the way the types of steps arguments are "inferred" by Cucumber Scala.
The main difficulity being generic types like
List[Map[String, String]]
(used for instance for datatables).Current situation (Scala 2)
We rely on the scala reflection
Manifest
mechanism which overcome the JVM type erasure.In recent Scala 2 versions,
Manifest
s are deprecated but still available. The replacement beingTypeTag
s which could be used in a very similary way.Future (Scala 3)
With Scala 3, both
Manifest
andTypeTag
s are removed with no direct replacement.I tried to mimic the behaviour by using macros in a previous PR (#186) thanks to a home made library (typetrees). This was working but:
Proposition
This PR changes the way we infer types by using a well-known typeclass mechanism.
Argument of a step must have a type
T
that conforms to the typeclassStepable[T]
. This typeclass being defined as:Implicit values of
Stepable
are provided for all non generic types and generic types with less than 10 parameters (any combination of these being possible).This might sound like we are reducing the possibilities of types allowed in step arguments and it is the case for generic types with more than 9 parameters but:
TODO
Stepable
implicitsAdditional note: we still need a slightly different code in
StepDsl
between Scala 2 and Scala 3 but not related to the types of step arguments, only to some construction not allowed anymore in Scala 3 for handling bothfn: => Unit
andfn: () => Unit
.