[
https://issues.apache.org/jira/browse/GROOVY-12773?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King updated GROOVY-12773:
-------------------------------
Component/s: Static Type Checker
> STC: an argument of a generic call is not checked against a type argument
> that the target gives in terms of a bounded type parameter of the calling
> method
> ----------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12773
> URL: https://issues.apache.org/jira/browse/GROOVY-12773
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Affects Versions: 4.0.33, 5.1.3, 6.0.0
> Reporter: Paul King
> Priority: Major
>
> {code:groovy}
> @groovy.transform.CompileStatic
> class C {
> static <U extends Number> List<Class<? extends U>> classes(Class<?
> extends Number> c) {
> List<Class<? extends U>> list = Collections.singletonList(c)
> list
> }
> static String hex(Integer i) { Integer.toHexString(i) }
> static main(args) {
> List<Class<? extends Integer>> list = classes(Double)
> println hex(list[0].getConstructor(String).newInstance('1'))
> }
> }
> {code}
> This compiles with 4.0.33, 5.1.3, 6.0.0 and master. The target gives
> {{singletonList}}'s {{T}} as {{Class<? extends U>}}, but the argument, a
> {{Class<? extends Number>}}, is not checked against it, so a
> {{Class<Double>}} is returned as a {{Class<? extends Integer>}}. Under
> {{@TypeChecked}} the call of {{hex}} then fails with {{MissingMethodException
> ... argument types: (Double)}}. Under {{@CompileStatic}} it prints {{1}},
> because the {{Double}} is converted silently.
> javac rejects the equivalent: "inference variable T has incompatible bounds".
> *Expected:* a compile error. When the target gives a type parameter a type
> that still mentions a type variable of the calling method, here {{U}}, the
> arguments must be checked against it as for a fully known type, without
> widening {{U}} to its bound.
> This is related to GROOVY-12766, where the arguments of a generic call are
> not checked against an explicit or inferred type argument. Here the type
> argument comes from the assignment target. A {{@NotYetImplemented}} test,
> {{GenericsSTCTest#testArgumentIsCheckedAgainstBoundOfEnclosingTypeParameter}},
> records this in PR #3293.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)