[jira] [Commented] (GROOVY-9033) Bad code green: empty list literal with each method

2021-03-31 Thread Daniil Ovchinnikov (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9033?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17312724#comment-17312724
 ] 

Daniil Ovchinnikov commented on GROOVY-9033:


{code:groovy}
@groovy.transform.CompileStatic
List usage() {
  def l = [].each {}
  l.add(new Object())
  return l
}
{code}

> Bad code green: empty list literal with each method
> ---
>
> Key: GROOVY-9033
> URL: https://issues.apache.org/jira/browse/GROOVY-9033
> Project: Groovy
>  Issue Type: Bug
>  Components: Static Type Checker
>Affects Versions: 2.5.6
>Reporter: Daniil Ovchinnikov
>Priority: Major
>
> {code:groovy}
> @groovy.transform.CompileStatic
> List usage() {
>   def l = [].each {}
>   return l // expected error: Incompatible generic argument types. Cannot 
> assign java.util.List  to: java.util.List  
> }{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (GROOVY-9033) Bad code green: empty list literal with each method

2021-03-30 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9033?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17311641#comment-17311641
 ] 

Eric Milles commented on GROOVY-9033:
-

Because the variable still carries unresolved type parameters to the return 
site, it gets treatment like "return []" or "return Collections.emptyList()".  
If you change "def" to "List" an error will occur for the return 
statement.

Are you seeing a case where the list is non-empty and there is not a return 
type error?

> Bad code green: empty list literal with each method
> ---
>
> Key: GROOVY-9033
> URL: https://issues.apache.org/jira/browse/GROOVY-9033
> Project: Groovy
>  Issue Type: Bug
>  Components: Static Type Checker
>Affects Versions: 2.5.6
>Reporter: Daniil Ovchinnikov
>Priority: Major
>
> {code:groovy}
> @groovy.transform.CompileStatic
> List usage() {
>   def l = [].each {}
>   return l // expected error: Incompatible generic argument types. Cannot 
> assign java.util.List  to: java.util.List  
> }{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)