pjfanning opened a new pull request, #3717:
URL: https://github.com/apache/pekko/pull/3717

   ### Motivation
   Most stream javadsl operators take invariant `japi.function` types, so a 
Java caller cannot pass an existing `Function<Object, String>`, 
`Predicate<Number>` or `Function2<Number, Number, Integer>` where the element 
or result type differs, even though the call is type safe. `java.util.stream` 
uses `Function<? super T, ? extends R>`, `Predicate<? super T>` and `Supplier<? 
extends T>` throughout, and #3713/#3714 already widened part of the javadsl, 
leaving the remaining operators inconsistent (see the follow-up comment on 
#3714).
   
   Inline lambdas and method references already adapt to the target type, so 
the practical gain is for function values that are already typed (fields, 
helpers, functions from other APIs); the main argument is consistency with JDK 
conventions.
   
   ### Modification
   - Across the stream javadsl (`Source`, `Flow`, `Sink`, `SubFlow`, 
`SubSource`, `FlowWithContext`, `SourceWithContext`, `BidiFlow`, `Graph`, 
`Hub`, `Restart*`, `RetryFlow`, `Tcp`, `TLS`, `StreamConverters`, `Framing`), 
widen method parameters:
     - `Function[A, B]` → `Function[? >: A, ? <: B]`
     - `Function2[A, B, C]` → `Function2[? >: A, ? >: B, ? <: C]`
     - `Creator[T]` → `Creator[? <: T]`
     - `Predicate[T]` → `Predicate[? >: T]`
   - Type arguments that already had a wildcard are unchanged, and no bound is 
added where it cannot widen anything (e.g. `? <:` on final types such as 
`Boolean`, `String` or `NotUsed`).
   - Add explicit type arguments at the few internal call sites where Scala can 
no longer infer them (`combinerToScala`, `Flow.fromFunction`).
   - Add MiMa excludes (`IncompatibleSignatureProblem` only) for the generic 
signature changes.
   
   ### Result
   Java callers can pass function values typed over a supertype of the input or 
a subtype of the result without casts. Erasure is unchanged, so the change is 
binary compatible.
   
   ### Tests
   - `sbt "stream/compile" "++3.3.8 stream/compile"` - passed
   - `sbt Test/compile` for `stream-tests`, `stream-typed`, `stream-testkit`, 
`persistence-query`, `persistence-testkit`, `persistence-typed-tests` (Scala 
2.13) - passed
   - `sbt "stream/mimaReportBinaryIssues"` - passed with the added excludes
   - New directional tests (`mustAcceptFunctionsOverWiderAndNarrowerTypes` in 
`SourceTest`/`FlowTest`/`SinkTest`, 
`mustAcceptConcreteSourceCreatorsInRestartSource`) not run locally - left to 
CI, along with `docs`/`cluster-sharding-typed` compilation and Scala 3 test 
compilation
   
   ### References
   Refs #3712, #3713, #3714


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to