From notifications-return-16019-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Wed Apr 3 15:48:04 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 [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 7BA70180600 for ; Wed, 3 Apr 2019 17:48:03 +0200 (CEST) Received: (qmail 63935 invoked by uid 500); 3 Apr 2019 15:48:01 -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 63828 invoked by uid 99); 3 Apr 2019 15:48:01 -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; Wed, 03 Apr 2019 15:48:01 +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 D3BE0E2A07 for ; Wed, 3 Apr 2019 15:48: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 3D8492459F for ; Wed, 3 Apr 2019 15:48:00 +0000 (UTC) Date: Wed, 3 Apr 2019 15:48:00 +0000 (UTC) From: "Eric Milles (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= 08861#comment-16808861 ]=20 Eric Milles commented on GROOVY-9064: ------------------------------------- To maintain the declared type, I propose the following change in {{StaticTy= peCheckingVisitor.visitBinaryExpression}}: {code:java} if (!isEmptyDeclaration && isAssignment(op)) { ... // GRECLIPSE add if (!(leftExpression instanceof VariableExpression) || ((Va= riableExpression) leftExpression).isDynamicTyped()) // GRECLIPSE end storeType(leftExpression, resultType); {code} It is possible another condition should be added for assignment to property= expressions as well, like {{foo.bar =3D value}}. In any case, this is a s= ignificant enough STC change that I believe it should not be made in Groovy= 2.5, but can be made in Groovy 3+. > 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: Bug > 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)