groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marshall, Simon" <Simon.Marsh...@misys.com>
Subject RE: Groovy runtime issue with multiple directories install
Date Wed, 23 Mar 2016 09:13:21 GMT
The name of the enum is Gender, not Sex, so the decl of gender in C1 looks dubious.  The error
message (referring to Sex) doesn’t match the code (using Gender), so I’m wondering if
the error message wasn’t a result of the version of the code you pasted below?

From: DECLOEDT Loic EVADERIS [mailto:Loic.DECLOEDT@cea.fr]
Sent: 23 March 2016 09:02
To: users@groovy.apache.org
Cc: PAOLI Pierre EVADERIS; GUIU Vincent EVADERIS
Subject: Groovy runtime issue with multiple directories install

Hi,
I have a problem starting up a groovy project structured like this:
project/
 classes/
   person/
      C1.groovy
  scripts
   run.groovy

The C1.groovy file contains the following code:
package person
import groovy.transform.ToString

@ToString
class C1 {
  enum Gender { M, F}

  String name
  Sex gender
}

And the run.groovy file contains the following code:
import person.C1
//import person.C1.Gender
def m = person.C1.Gender.M
def f = person.C1.Gender.F
println "genders: ${m}, ${f}"

abstract class CScript extends groovy.lang.Script {
  public C1 addC1(String name, person.C1.Gender g) {
    return new C1(name:name, gender:g)
  }
}

def c = new C1(name: "max", gender: person.C1.Gender.M)

println "c = ${c}"

I have the following error when executing this code with the following command from the project
dir:
groovy -cp $PWD/classes scripts/run.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/home/ldecloed/Groovy/workspace/issueImportEnum/scripts/run.groovy: 13: unable to resolve
class person.C1.Sex
 @ line 13, column 32.
     public C1 addC1(String name, person.C1.Sex g) {
                                  ^

1 error

However, all errors disapear when commenting out the whole CScript class declaration.  As
a result, the person.C1.Sex enum can be used outside the CScript class declaration but not
inside.
In addtion, I tested a static compilation of the whole code and it works correctly in this
case.
Can you clarify whether this code is valid ? If so, do you plan to improve groovy to support
it ?
This test has been made with groovy 2.4.6. I can provide the sources if you want a test-case.

Regards,
Loïc.

--
Loïc Decloedt
CAD & Software Manager
eVaderis
[eVaderis-logo-CMJN-small1]

Minatec Entreprise BHT
7, Parvis Louis Néel
38054 Grenoble Cedex 9
France
Office : 04 38 7 80874

"Misys" is the trade name of the Misys group of companies. This email and any attachments
have been scanned for known viruses using multiple scanners. This email message is intended
for the named recipient only. It may be privileged and/or confidential. If you are not the
named recipient of this email please notify us immediately and do not copy it or use it for
any purpose, nor disclose its contents to any other person. This email does not constitute
the commencement of legal relations between you and Misys. Please refer to the executed contract
between you and the relevant member of the Misys group for the identity of the contracting
party with which you are dealing.

Mime
View raw message