You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2022/06/27 17:17:00 UTC
[jira] [Resolved] (GROOVY-10667) Wrong Type-Inference in `instanceof` block
[ https://issues.apache.org/jira/browse/GROOVY-10667?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles resolved GROOVY-10667.
----------------------------------
Fix Version/s: 5.0.0-alpha-1
Resolution: Fixed
https://github.com/apache/groovy/commit/52dca7df41c2935521a21bc6537c86691a69eb7c
> Wrong Type-Inference in `instanceof` block
> ------------------------------------------
>
> Key: GROOVY-10667
> URL: https://issues.apache.org/jira/browse/GROOVY-10667
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation
> Affects Versions: 4.0.3
> Environment: I tried Java 8 and 17. Both from a Gradle 7.1 project.
> Reporter: Jan Hackel
> Assignee: Eric Milles
> Priority: Major
> Fix For: 5.0.0-alpha-1
>
>
> Groovy 4.0.3 produces the error
> {{[Static type checking] - Cannot find matching method de.jhunovis.instance_of.MethodArgumentTypeInferenceErrorTest#doSomethingWithException(de.jhunovis.instance_of.MethodArgumentTypeInferenceErrorTest$Tagged). Please check if the declared type is correct and if the method exists.}}
> for this piece of code:
> {code:groovy}
> import groovy.transform.CompileStatic
> @CompileStatic
> class MethodArgumentTypeInferenceErrorTest {
> private static interface Tagged {
> String getTag()
> }
> private static class TaggedException extends RuntimeException implements Tagged {
> String tag
> }
> void cannotFindMatchingMethod() {
> doSomethingWith(new TaggedException(tag: 'Test'))
> }
> private static void doSomethingWith(Exception e) {
> if (e instanceof Tagged) {
> println e.tag
> doSomethingWithException(e)
> }
> }
> private static void doSomethingWithException(Exception exception) {
> }
> }
> {code}
> It seems the `instanceof` confuses the type-inference.
--
This message was sent by Atlassian Jira
(v8.20.7#820007)