From notifications-return-10918-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Thu Feb 1 07:42:08 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id 02367180652 for ; Thu, 1 Feb 2018 07:42:08 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id E67D1160C44; Thu, 1 Feb 2018 06:42:07 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 3CD60160C26 for ; Thu, 1 Feb 2018 07:42:07 +0100 (CET) Received: (qmail 63530 invoked by uid 500); 1 Feb 2018 06:42:06 -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 63521 invoked by uid 99); 1 Feb 2018 06:42:06 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Feb 2018 06:42:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 80A37DE4C9 for ; Thu, 1 Feb 2018 06:42:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -109.511 X-Spam-Level: X-Spam-Status: No, score=-109.511 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id sIWcBUp9n9XA for ; Thu, 1 Feb 2018 06:42:03 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 7D4F25FC3C for ; Thu, 1 Feb 2018 06:42:02 +0000 (UTC) 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 56BCFE019C for ; Thu, 1 Feb 2018 06:42:01 +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 8F2DD23373 for ; Thu, 1 Feb 2018 06:42:00 +0000 (UTC) Date: Thu, 1 Feb 2018 06:42:00 +0000 (UTC) From: "Paul King (JIRA)" To: notifications@groovy.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (GROOVY-6629) static compilation fails with obscure message when only constructor is annotated MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/GROOVY-6629?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16348088#comment-16348088 ] Paul King edited comment on GROOVY-6629 at 2/1/18 6:41 AM: ----------------------------------------------------------- Here is the comment about this message from {{StaticCompilationVisitor#checkForConstructorWithCSButClassWithout}}: {code} /** * If we are in a constructor, that is static compiled, but in a class, that * is not, it may happen that init code from object initializers, fields * or properties is added into the constructor code. The backend assumes * a purely static constructor, so it may fail if it encounters dynamic * code here. Thus we make this kind of code fail */ {code} And a simpler example to trigger the error: {code} class TestBroken { private myField @groovy.transform.CompileStatic TestBroken() {} } {code} We could certainly improve the error message and in fact even without fixing the underlying issue, we could be a lot smarter. In my smaller example for instance, even though we have a field, we don't have an initial value expression, so it would be safe to statically compile this example. was (Author: paulk): Here is the comment about this message from {{StaticCompilationVisitor#checkForConstructorWithCSButClassWithout}}: {code} /** * If we are in a constructor, that is static compiled, but in a class, that * is not, it may happen that init code from object initializers, fields * or properties is added into the constructor code. The backend assumes * a purely static constructor, so it may fail if it encounters dynamic * code here. Thus we make this kind of code fail */ {code} And a simpler example to trigger the error: {code} class TestBroken { private myField @groovy.transform.CompileStatic TestBroken() {} } {code} > static compilation fails with obscure message when only constructor is annotated > -------------------------------------------------------------------------------- > > Key: GROOVY-6629 > URL: https://issues.apache.org/jira/browse/GROOVY-6629 > Project: Groovy > Issue Type: Bug > Components: Static compilation > Affects Versions: 2.2.2, 2.3.0, 2.4.0-rc-1 > Reporter: Dimitar Dimitrov > Priority: Major > > {code} > class TestBroken { > private final InetAddress bindTo > @groovy.transform.CompileStatic > TestBroken(InetAddress bindTo = null) { > this.bindTo = bindTo ?: InetAddress.getByName("localhost") > } > } > {code} > Error:(12, 5) Groovyc: [Static type checking] - Cannot statically compile constructor implicitly including non static elements from object initializers, properties or fields. > {code} > @groovy.transform.CompileStatic > class TestWorking { > private final InetAddress bindTo > TestWorking(InetAddress bindTo = null) { > this.bindTo = bindTo ?: InetAddress.getByName("localhost") > } > } > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)