paulk-asert commented on PR #3293: URL: https://github.com/apache/groovy/pull/3293#issuecomment-6940015941
Thanks, Daniel. Both programmes are now compile errors, and your reading of where they were accepted was right in each case. The tip is c5627befab. On the baseline again: neither was newly accepted. 5.1.3 and 6.0.0 compile both and behave as the tip you reviewed did. Master rejects them, but it rejects the legal forms beside them too. โ compiles and runs ยท โ compile error ยท ๐ฅ compiles, then fails or leaves a `String` in a list of numbers | Case | 5.1.3, 6.0.0 | master | reviewed tip | this tip | javac | |---|---|---|---|---|---| | `Supplier<List<String>> s = toSupplier(C::nil)` | ๐ฅ | โ | ๐ฅ | โ | โ | | `Supplier<List<Integer>> s = toSupplier(C::nil)` | โ | โ | โ | โ | โ | | `Consumer<String> c = toConsumer(identC(C::takeNumber))` | ๐ฅ | โ | ๐ฅ | โ | โ | | `Consumer<Integer> c = toConsumer(identC(C::takeNumber))` | โ | โ | โ | โ | โ | **Your first programme.** A type parameter of the referenced method that the parameters of the functional interface leave open is now taken from what it returns, and checked against its bound, as you suggested. That also rejects your `nilOf` and `emptyMap` forms, the method pointer form and `Supplier<Collection<String>>`. `Supplier<List<? extends Number>>` and an unbounded method such as `Collections::emptyList` still compile. **Your second programme.** A nested generic call that its own arguments leave open is now typed by the parameter in turn, so the target reaches the reference. Both orders of nesting are rejected, and `toFn(toFn(Arrays::asList))` compiles and runs. **A grid, in place of one programme at a time.** Finding these one at a time was not going to converge, so there is now a grid of programmes as a test, `FunctionalTargetTypingSTCTest`, and the description has a section, "A grid of programs", with its two tables: every combination of where the type parameter is constrained, what carries it and where the target comes from, legal and illegal, for the releases and for this tip. A programme is illegal if the target gives the type parameter a type outside its bound, and each one goes on to fail at run time, which the test checks, so none is only a rule of Java that Groovy does not share. The programmes that do not yet behave as they should are listed in the test by cause and are checked to behave as listed, so a change that moves one either way fails. What the tables show: - Every difference from the releases is in the right direction but one, and that one is explained there: the releases rejected it only together with its legal form. - The grid found a regression of this branch against the releases, which is fixed: a method pointer to a method that returns its type parameter, `Function<Integer, Integer> f = toFunction(C.&same)`, was rejected. - What is left falls into a few whole rows and columns, each with one cause: GROOVY-12777, GROOVY-12778, a bound that is not checked outside a generic call with a target (the direct form you set aside, and the root of your first programme), and a lambda parameter without a type. None is changed here, and all are the same in 5.1.3 and 6.0.0. **Conversions.** One group is deliberately not an error. Groovy converts a value where it moves into a declared type, so `String s = C.zero()` is legal for `<T extends Number> T zero()`: the type parameter is a `Number` and the result is then converted, as if `toString()` were written. The rule the grid follows is that such a programme is sound if it is sound with the conversion written out. A type argument is not such a place, so a `GString` in a `List<String>` is still an error. Where a lambda or reference returns to a functional interface that declares a `String`, the conversion is accepted but not always made; that is GROOVY-12783, which is about making it, not about rejecting the programme. Jochen's two comments on the inner class name are fixed in the tip. The root test suite, `:checkstyleMain` and `:codenarcTest` pass locally on it. I'd be glad of another look. -- 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]
