From notifications-return-16060-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Sun Apr 7 14:05:02 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id C748718061A for ; Sun, 7 Apr 2019 16:05:01 +0200 (CEST) Received: (qmail 74058 invoked by uid 500); 7 Apr 2019 13:45:23 -0000 Mailing-List: contact notifications-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list notifications@groovy.apache.org Received: (qmail 74048 invoked by uid 99); 7 Apr 2019 13:45:23 -0000 Received: from mailrelay1-us-west.apache.org (HELO mailrelay1-us-west.apache.org) (209.188.14.139) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 07 Apr 2019 13:45:23 +0000 Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 63382E01AC for ; Sun, 7 Apr 2019 14:05:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 1EB4F24595 for ; Sun, 7 Apr 2019 14:05:00 +0000 (UTC) Date: Sun, 7 Apr 2019 14:05:00 +0000 (UTC) From: "Mauro Molinari (JIRA)" To: notifications@groovy.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (GROOVY-9064) STC: explicit declared variable type ignored in favor of assigned value type(s) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/GROOVY-9064?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D168= 11893#comment-16811893 ]=20 Mauro Molinari commented on GROOVY-9064: ---------------------------------------- Thanks for the pointer Paul, I now understand this better. Personally, from= a fan of statically typed languages, I find it a bit confusing and risky, = but I understand the point when the documentation says that flow typing was= introduced to reduce the difference in semantics between classic and stati= c Groovy. So, from this point of view, the behaviour of groovyc with the example prov= ided in the steps to repro is perfectly correct. However, given the fact that {{List}} is often a shortcut for "list of I do= n't care of", rather than "list of Objects" (so, something more like {{List= }} rather than {{List}}), I think that in this specific case (wh= ich is something like the opposite of the example provided by the documenta= tion, {{List list =3D ['a','b','c']}}, where the declared type is less spec= ific than the inferred type), where the generic type is made more specific = and explicit by the declared type of {{rows}} variable, having such a behav= iour is not only counter-intuitive, but even questionable... What do you think? > STC: explicit declared variable type ignored in favor of assigned value t= ype(s) > -------------------------------------------------------------------------= ------ > > Key: GROOVY-9064 > URL: https://issues.apache.org/jira/browse/GROOVY-9064 > Project: Groovy > Issue Type: Improvement > Reporter: Eric Milles > Priority: Major > > Follow up to GROOVY-9058.=C2=A0 Consider the following: > {code:groovy} > List getSomeRows() { ... } > @groovy.transform.CompileStatic > void meth() { > List rows =3D getSomeRows() > rows.each { row -> > def col =3D row[0] > } > } > {code} > The inferred type of {{rows}} is {{List}} and not {{List}} even= though the assignment cleared type checking. This causes the inferred typ= e of {{row}} to be {{Object}} instead of {{Object[]}}. > Similarly, {{List list =3D []}} infers as {{ArrayList}} i= nstead of the explicit declared type, and {{Map map =3D [:]}} in= fers to {{LinkedHasMap<...>}} instead of the declared type. In general, I = think as long as the assignment is compatible, the variable should retain i= ts explicitly declared type regardless of assignments. -- This message was sent by Atlassian JIRA (v7.6.3#76005)