[jira] [Commented] (GROOVY-9599) CliBuilder: Option with "type: String, defaultValue ''" (empty String) results in NullObject if default value is applied

2020-06-21 Thread Dirk Heinrichs (Jira)


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

Dirk Heinrichs commented on GROOVY-9599:


Great, thanks a lot [~rpopma]!

> CliBuilder: Option with "type: String, defaultValue ''" (empty String) 
> results in NullObject if default value is applied
> 
>
> Key: GROOVY-9599
> URL: https://issues.apache.org/jira/browse/GROOVY-9599
> Project: Groovy
>  Issue Type: Bug
>  Components: command line processing
>Affects Versions: 2.5.11, 3.0.4
>Reporter: Remko Popma
>Assignee: Remko Popma
>Priority: Major
> Fix For: 3.0.5, 2.5.13
>
>
> This is a follow-up ticket for GROOVY-9519:
> After checking with Groovy 3.0.4, it seems that only the "Integer with 
> defaultValue '0'" case was fixed, but not "String with defaultValue ''". The 
> latter became even worse. It still ignores the defaultValue, but instead of 
> creating a Boolean, it now creates a NullObject. Try this code:
> {code:java}
> @Grab('info.picocli:picocli-groovy:4.3.2')
> @GrabConfig(systemClassLoader=true)
> import groovy.cli.picocli.CliBuilder
> def cli = new CliBuilder(name: 'cliTest.groovy', stopAtNonOption: false)
> cli.h(type: Boolean, longOpt: 'help', usageHelp: true, required: false, 'Show 
> usage information')
> cli.a(type: String, longOpt: 'optA', required: false, args: 1, defaultValue: 
> '', 'Option a (optional)')
> def opts = cli.parse(args)
> opts || System.exit(1)
> if(opts.h) {
>   cli.usage()
>   System.exit(0)
> }
> println(opts.a.getClass())
> if (opts.a) {
>   println(opts.a)
> }
> {code}
> with Groovy 3.0.2:
> {code:java}
> % ~/tmp/groovy-3.0.2/bin/groovy ./cliTest.groovy
> class java.lang.Boolean
> {code}
> and with Groovy 3.0.4:
> {code:java}
> % ~/tmp/groovy-3.0.4/bin/groovy ./cliTest.groovy
> class org.codehaus.groovy.runtime.NullObject
> {code}



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


[jira] [Commented] (GROOVY-9596) Cannot access protected field of Java superclass with --illegal-access=deny

2020-06-21 Thread Paul King (Jira)


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

Paul King commented on GROOVY-9596:
---

Using `this.@in` or `super.@in` results (for both static and dynamic variants) 
in:
{code}
getfield  #gg// Field 
java/io/FilterReader.in:Ljava/io/Reader;
{code}
So, that would be the correct workaround for now.

> Cannot access protected field of Java superclass with --illegal-access=deny
> ---
>
> Key: GROOVY-9596
> URL: https://issues.apache.org/jira/browse/GROOVY-9596
> Project: Groovy
>  Issue Type: Bug
>  Components: bytecode
>Affects Versions: 3.0.4, 2.5.12
> Environment: JDK 14
> Groovy 2.5.12 or 3.0.4
>Reporter: Kevin Rushforth
>Priority: Major
> Attachments: Main.groovy, Main2.groovy, MyAWTEvent.groovy, 
> MyFilterReader.groovy
>
>
> When using the Java option {{--illegal-access=deny}}, a Groovy subclass that 
> extends a Java superclass in the Java runtime (e.g., a class in the 
> {{java.base}} module) cannot access a protected field in the parent class 
> using {{this.fieldName}}.
> To reproduce this bug, use JDK 14 (or later) and run the following using 
> either Groovy 2.5.12 or 3.0.4:
> {{$ groovyc Main.groovy MyFilterReader.groovy}}
>  {{$ _JAVA_OPTIONS="--illegal-access=deny" groovy Main}}
> It works correctly without {{--illegal-access=deny}}. You can add 
> {{-Dsun.reflect.debugModuleAccessChecks=access}} to get more detailed 
> information about the illegal access exceptions that are being swallowed by 
> Groovy.
> {{$ _JAVA_OPTIONS="--illegal-access=deny 
> -Dsun.reflect.debugModuleAccessChecks=access" groovy Main}}
> WORKAROUND: change the following line in the Groovy subclass:
> line = ((BufferedReader)this.in).readLine();
> to:
> line = ((BufferedReader)super.in).readLine();



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


[jira] [Commented] (GROOVY-4856) Closure resolveStrategy does not work the same way for properties and methods

2020-06-21 Thread Eric Milles (Jira)


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

Eric Milles commented on GROOVY-4856:
-

AsmClassGenerator checks for "this", "super" or defined variables before 
anything else.
{code:java}
public void visitVariableExpression(final VariableExpression expression) {
final String variableName = expression.getName();

if (expression.isThisExpression()) {
...
}

if (expression.isSuperExpression()) {
...
}

BytecodeVariable variable = 
controller.getCompileStack().getVariable(variableName, false);
if (variable != null) {
controller.getOperandStack().loadOrStoreVariable(variable, 
expression.isUseReferenceDirectly());
} else ...
{code}

I'm not sure if it is intended behavior to have local or script variables take 
precedence over delegate or owner properties.  However, you can add a 
"delegate." qualifier to disambiguate.

> Closure resolveStrategy does not work the same way for properties and methods
> -
>
> Key: GROOVY-4856
> URL: https://issues.apache.org/jira/browse/GROOVY-4856
> Project: Groovy
>  Issue Type: Bug
>  Components: Compiler
>Affects Versions: 1.7.6
> Environment: Mac OS 10.6.7, Groovy installed via Ports
>Reporter: Guven Demir
>Priority: Major
>
> When the resolveStrategy is set to DELEGATE_FIRST and the delegate is set 
> property, a method with the same name as a global function is preferred 
> instead of the global function. The same is not true for properties.
> The following code fragment demonstrates this issue:
> -
> {noformat}
> class ClosureTest
> {
> def someProperty = ""
> def anotherProperty = ""
> public void test(Closure closure)
> {
> closure.delegate = this
> closure.resolveStrategy = Closure.DELEGATE_FIRST
> closure()
> }
> 
> public void someMethod()
> {
> println "ClosureTest.someMethod()"
> }
> public void anotherMethod()
> {
> println "ClosureTest.anotherMethod()"
> }
> 
> public String toString()
> {
> return "ClosureTest: sp: " + someProperty + ", ap: " + anotherProperty
> }
> }
> def someProperty = "global someProperty"
> public void someMethod()
> {
> println "global someMethod()"
> }
> def ct = new ClosureTest()
> ct.test() {
> someMethod()
> anotherMethod()
> someProperty = "foo"
> anotherProperty = "bar"
> }
> println "ct.someProperty : ${ct.someProperty}"
> println "ct.anotherProperty  : ${ct.anotherProperty}"
> println "global: someProperty: " + someProperty
> {noformat}
> -
> And the output of this script run is:
> {noformat}
> ClosureTest.someMethod()
> ClosureTest.anotherMethod()
> ct.someProperty : 
> ct.anotherProperty  : bar
> global: someProperty: foo
> {noformat}
> -
> As seen above, the methods are called correctly, but the properties are not 
> set correctly.



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


[jira] [Commented] (GROOVY-7480) ClosureMetaClass wrong routing calls logic

2020-06-21 Thread Eric Milles (Jira)


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

Eric Milles commented on GROOVY-7480:
-

When making an implicit-this method call from within a closure, methods on 
Closure itself take precedence.  This is so you can call "getDelegate()" or 
"trampoline()" for example.  In this case, you are effectively calling 
"c.leftShift('*')", since leftShift is a method implemented by 
groovy.lang.Closure.

You can add a "delegate." or "getDelegate()." qualifier to your leftShift call 
to direct it away from Closure.

{code:java}
/**
 * Alias for calling a Closure for non-closure arguments.
 * 
 * Typical usage:
 * 
 * def times2 = { a {@code ->} a * 2 }
 * def add3 = { a {@code ->} a + 3 }
 * assert add3 {@code <<} times2 {@code <<} 3 == 9
 * 
 *
 * @param arg the argument to call the closure with
 * @return the result of calling the Closure
 */
public V leftShift(final Object arg) {
return call(arg);
}
{code}

> ClosureMetaClass wrong routing calls logic
> --
>
> Key: GROOVY-7480
> URL: https://issues.apache.org/jira/browse/GROOVY-7480
> Project: Groovy
>  Issue Type: Bug
>  Components: groovy-runtime
>Affects Versions: 2.4.2
>Reporter: Paolo Piersanti
>Priority: Major
>
> Setting up the resolve strategy to Closure.DELEGATE_FIRST does not
> get the delegate looked up at first. For instance:
> target = 'aTarget'
> c = new GroovyShell().evaluate("{ -> leftShift('*') }");
> c.resolveStrategy = Closure.DELEGATE_FIRST
> c.delegate = target
> c.call() 
> results in 
> groovy.lang.MissingMethodException: No signature of method:
> Script1$_run_closure1.doCall() is applicable for argument types:
> (java.lang.String) values: [*]
> Possible solutions: doCall(), findAll(), findAll(),
> isCase(java.lang.Object), isCase(java.lang.Object)
> at Script1$_run_closure1.doCall(Script1.groovy:1)
> at ConsoleScript33.run(ConsoleScript33:5) 



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


[jira] [Commented] (GROOVY-9605) leftShift operator does not work on BigInteger (throws UnsupportedOperationException)

2020-06-21 Thread Paul King (Jira)


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

Paul King commented on GROOVY-9605:
---

Both leftShift and rightShift can be accommodated for BigInteger by adjusting 
BigIntegerMath as you spotted. It's an easy change which I have made locally. 
I'll just check tests and doco before creating a PR for review.

> leftShift operator does not work on BigInteger (throws 
> UnsupportedOperationException)
> -
>
> Key: GROOVY-9605
> URL: https://issues.apache.org/jira/browse/GROOVY-9605
> Project: Groovy
>  Issue Type: Bug
>  Components: groovy-jdk
>Affects Versions: 3.0.4
> Environment: Groovy 3.0.4 Windows and Linux
>Reporter: Bertrand Martin
>Assignee: Paul King
>Priority: Major
>
> h1. Problem
> The _leftShift_ operator ({{<<}}) does not work on *BigInteger* (see 
> [StackOverflow 
> question|https://stackoverflow.com/questions/62496971/leftshift-method-on-biginteger-in-groovy]).
> The *leftShift()* method is however described in [Groovy's JDK 
> enhancements|http://docs.groovy-lang.org/latest/html/api/org/codehaus/groovy/runtime/DefaultGroovyMethods.html#leftShift(java.lang.Number,java.lang.Number)].
> The below code fails with Groovy 3.0.4:
> {code:groovy}
> Integer i = new Integer(3)
> assert 12 == i << 2
> Number b = new BigInteger("3")
> assert 12 == b << 2
> {code}
> It throws an exception:
> {noformat}
> Caught: java.lang.UnsupportedOperationException: Cannot use leftShift() on 
> this number type: java.math.BigInteger with value: 3
> java.lang.UnsupportedOperationException: Cannot use leftShift() on this 
> number type: java.math.BigInteger with value: 3
> at test.run(test.groovy:5)
> {noformat}
> Consequence: you cannot use the {{<<}} operator on a _Number_ if this number 
> is a _BigInteger_.
> h1. Understanding of the problem
> (I'm not familiar with the code)
> The 
> [BigIntegerMath|https://github.com/groovy/groovy-core/blob/master/src/main/org/codehaus/groovy/runtime/typehandling/BigIntegerMath.java]
>  class does not implement the _leftShift()_ method.
> Also, please note that JDK's 
> [BigInteger|https://docs.oracle.com/javase/8/docs/api/java/math/BigInteger.html#shiftLeft-int-]
>  method for this operation is *not* _leftShift()_ but _shiftLeft()_!
> h1. Workaround
> Using mixins, the below code works:
> {code:groovy}
> class EnhancedNumber {
>   static def originalLeftShift = 
> org.codehaus.groovy.runtime.DefaultGroovyMethods.
>   static Number leftShift(Number self, Number operand) {
>   self.class == BigInteger ? self.shiftLeft(operand) : 
> originalLeftShift(self, operand)
>   }
> }
> Number.mixin(EnhancedNumber)
> Integer i = new Integer(3)
> assert 12 == i << 2
> Number b = new BigInteger("3")
> assert 12 == b << 2
> {code}



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


[GitHub] [groovy] eric-milles opened a new pull request #1286: GROOVY-8274: allow user-supplied methodMissing in non-static inner class

2020-06-21 Thread GitBox


eric-milles opened a new pull request #1286:
URL: https://github.com/apache/groovy/pull/1286


   InnerClassCompletionVisitor overwrote user's methodMissing or 
propertyMissing with synthetic dispatcher.
   
   https://issues.apache.org/jira/browse/GROOVY-8274



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[jira] [Assigned] (GROOVY-8274) methodMissing not executed when the delegate is an inner class

2020-06-21 Thread Eric Milles (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-8274?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles reassigned GROOVY-8274:
---

Assignee: Eric Milles

> methodMissing not executed when the delegate is an inner class
> --
>
> Key: GROOVY-8274
> URL: https://issues.apache.org/jira/browse/GROOVY-8274
> Project: Groovy
>  Issue Type: Bug
>  Components: groovy-runtime
>Affects Versions: 2.4.12
>Reporter: James Kleeh
>Assignee: Eric Milles
>Priority: Major
>
> {code}
> class Foo {
> 
> void executeClosure(Closure c) {
> c.resolveStrategy = Closure.DELEGATE_ONLY
> c.delegate = new Bar()
> c.call()
> }
> class Bar {
> def methodMissing(String name, args) {
> println name
> }
> }
> }
> Closure c = {
> go()
> }
> new Foo().executeClosure(c)
> {code}
> Executing the above results in:
> {{groovy.lang.MissingMethodException: No signature of method: Foo.go() is 
> applicable for argument types: () values: []}}
> If the Bar class is moved out of Foo, it works as I expect.



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


[jira] [Assigned] (GROOVY-9605) leftShift operator does not work on BigInteger (throws UnsupportedOperationException)

2020-06-21 Thread Paul King (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-9605?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King reassigned GROOVY-9605:
-

Assignee: Paul King

> leftShift operator does not work on BigInteger (throws 
> UnsupportedOperationException)
> -
>
> Key: GROOVY-9605
> URL: https://issues.apache.org/jira/browse/GROOVY-9605
> Project: Groovy
>  Issue Type: Bug
>  Components: groovy-jdk
>Affects Versions: 3.0.4
> Environment: Groovy 3.0.4 Windows and Linux
>Reporter: Bertrand Martin
>Assignee: Paul King
>Priority: Major
>
> h1. Problem
> The _leftShift_ operator ({{<<}}) does not work on *BigInteger* (see 
> [StackOverflow 
> question|https://stackoverflow.com/questions/62496971/leftshift-method-on-biginteger-in-groovy]).
> The *leftShift()* method is however described in [Groovy's JDK 
> enhancements|http://docs.groovy-lang.org/latest/html/api/org/codehaus/groovy/runtime/DefaultGroovyMethods.html#leftShift(java.lang.Number,java.lang.Number)].
> The below code fails with Groovy 3.0.4:
> {code:groovy}
> Integer i = new Integer(3)
> assert 12 == i << 2
> Number b = new BigInteger("3")
> assert 12 == b << 2
> {code}
> It throws an exception:
> {noformat}
> Caught: java.lang.UnsupportedOperationException: Cannot use leftShift() on 
> this number type: java.math.BigInteger with value: 3
> java.lang.UnsupportedOperationException: Cannot use leftShift() on this 
> number type: java.math.BigInteger with value: 3
> at test.run(test.groovy:5)
> {noformat}
> Consequence: you cannot use the {{<<}} operator on a _Number_ if this number 
> is a _BigInteger_.
> h1. Understanding of the problem
> (I'm not familiar with the code)
> The 
> [BigIntegerMath|https://github.com/groovy/groovy-core/blob/master/src/main/org/codehaus/groovy/runtime/typehandling/BigIntegerMath.java]
>  class does not implement the _leftShift()_ method.
> Also, please note that JDK's 
> [BigInteger|https://docs.oracle.com/javase/8/docs/api/java/math/BigInteger.html#shiftLeft-int-]
>  method for this operation is *not* _leftShift()_ but _shiftLeft()_!
> h1. Workaround
> Using mixins, the below code works:
> {code:groovy}
> class EnhancedNumber {
>   static def originalLeftShift = 
> org.codehaus.groovy.runtime.DefaultGroovyMethods.
>   static Number leftShift(Number self, Number operand) {
>   self.class == BigInteger ? self.shiftLeft(operand) : 
> originalLeftShift(self, operand)
>   }
> }
> Number.mixin(EnhancedNumber)
> Integer i = new Integer(3)
> assert 12 == i << 2
> Number b = new BigInteger("3")
> assert 12 == b << 2
> {code}



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


[GitHub] [groovy] paulk-asert commented on pull request #1269: GROOVY-7971: do not save instanceof types under logical or

2020-06-21 Thread GitBox


paulk-asert commented on pull request #1269:
URL: https://github.com/apache/groovy/pull/1269#issuecomment-647243171


   I have been doing a few spikes but nothing finalised.
   
   I tried using Union and Intersection types to better model the type 
relationships. A logical OR with instanceof on both sides for example should 
have different semantics to a logical AND with instanceof on both sides. And 
we'd need a NotType as well at some point to have better handling of not in 
combination with instanceof for nested cases. I can get specific parts of our 
type checking processing to work as I'd hope with these in place but there are 
numerous places in the code which make different assumptions to what the new 
types would need. There are places where we ignore Object for instance which 
isn't what we'd now need but just removing the places where we make such tests 
breaks other things because various assumptions flow to other parts of the code.
   
   So, as an intermediate step, I have a slightly improved mechanism that looks 
for any IfStatement where the test is a binary logical OR and treats that as 
two individual IfStatement's corresponding to each half of the OR. It then does 
a separate pass to get the UnionType we currently expect for the AND case. The 
UnionType needs to be catered for so that we have an invokeDynamic instruction 
produced when @CS is in place. I think it will be a few more days before I have 
anything ready for review.



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[jira] [Commented] (GROOVY-9519) CLIBuilder: Option with "type: Integer, defaultValue '0'" results in Boolean if default value is applied

2020-06-21 Thread Remko Popma (Jira)


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

Remko Popma commented on GROOVY-9519:
-

[~dheinric], you are right, I did miss it when you raised it here originally. 
Thanks for following up!

> CLIBuilder: Option with "type: Integer, defaultValue '0'" results in Boolean 
> if default value is applied
> 
>
> Key: GROOVY-9519
> URL: https://issues.apache.org/jira/browse/GROOVY-9519
> Project: Groovy
>  Issue Type: Bug
>  Components: command line processing
>Affects Versions: 3.0.2
> Environment: WIndows/Linux
>Reporter: Dirk Heinrichs
>Assignee: Remko Popma
>Priority: Major
> Fix For: 3.0.4, 2.5.12
>
>
> When using an option with {{type: Integer}} and {{defaultValue: '0'}} the 
> resulting variable is of type Boolean if the option is not specified on the 
> command line. Here's a little Groovy program to demonstrate the issue:
> {code:java}
> @Grab('info.picocli:picocli-groovy:4.2.0')
> @GrabConfig(systemClassLoader=true)
> import groovy.cli.picocli.CliBuilder
> def cli = new CliBuilder(name: 'cliTest.groovy')
> cli.h(type: Boolean, longOpt: 'help', usageHelp: true, required: false, 'Show 
> usage information')
> cli.i(type: Integer, longOpt: 'intTest', required: false, args: 1, 
> defaultValue: '0', 'Testing integer with default value 0')
> def opts = cli.parse(args)
> opts || System.exit(1)
> if(opts.h) {
>   cli.usage()
>   System.exit(0)
> }
> println(opts.i.getClass())
> println(opts.i)
> // Need to explicitely convert if default value applies
> def i = (opts.i instanceof Boolean ? 0 : opts.i)
> println(i.getClass())
> println(i){code}
> Executing this w/o providing {{-i}} prints:
> {code}% ~/tmp/groovy-3.0.2/bin/groovy ./cliTest.groovy 
> class java.lang.Boolean
> false
> class java.lang.Integer
> 0{code}
> But if {{-i}} IS provided (even with the same value as the default), it 
> correctly prints:
> {code}% ~/tmp/groovy-3.0.2/bin/groovy ./cliTest.groovy -i 0
> class java.lang.Integer
> 0
> class java.lang.Integer
> 0{code}
> I would expect the type of {{opts.i}} to be Integer in both cases.
> NOTE: I've opened the same for PicoCLI, since I wasn't sure where it belongs.



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


[jira] [Resolved] (GROOVY-9599) CliBuilder: Option with "type: String, defaultValue ''" (empty String) results in NullObject if default value is applied

2020-06-21 Thread Remko Popma (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-9599?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Remko Popma resolved GROOVY-9599.
-
Resolution: Fixed

> CliBuilder: Option with "type: String, defaultValue ''" (empty String) 
> results in NullObject if default value is applied
> 
>
> Key: GROOVY-9599
> URL: https://issues.apache.org/jira/browse/GROOVY-9599
> Project: Groovy
>  Issue Type: Bug
>  Components: command line processing
>Affects Versions: 2.5.11, 3.0.4
>Reporter: Remko Popma
>Assignee: Remko Popma
>Priority: Major
> Fix For: 3.0.5, 2.5.13
>
>
> This is a follow-up ticket for GROOVY-9519:
> After checking with Groovy 3.0.4, it seems that only the "Integer with 
> defaultValue '0'" case was fixed, but not "String with defaultValue ''". The 
> latter became even worse. It still ignores the defaultValue, but instead of 
> creating a Boolean, it now creates a NullObject. Try this code:
> {code:java}
> @Grab('info.picocli:picocli-groovy:4.3.2')
> @GrabConfig(systemClassLoader=true)
> import groovy.cli.picocli.CliBuilder
> def cli = new CliBuilder(name: 'cliTest.groovy', stopAtNonOption: false)
> cli.h(type: Boolean, longOpt: 'help', usageHelp: true, required: false, 'Show 
> usage information')
> cli.a(type: String, longOpt: 'optA', required: false, args: 1, defaultValue: 
> '', 'Option a (optional)')
> def opts = cli.parse(args)
> opts || System.exit(1)
> if(opts.h) {
>   cli.usage()
>   System.exit(0)
> }
> println(opts.a.getClass())
> if (opts.a) {
>   println(opts.a)
> }
> {code}
> with Groovy 3.0.2:
> {code:java}
> % ~/tmp/groovy-3.0.2/bin/groovy ./cliTest.groovy
> class java.lang.Boolean
> {code}
> and with Groovy 3.0.4:
> {code:java}
> % ~/tmp/groovy-3.0.4/bin/groovy ./cliTest.groovy
> class org.codehaus.groovy.runtime.NullObject
> {code}



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


[jira] [Commented] (GROOVY-9599) CliBuilder: Option with "type: String, defaultValue ''" (empty String) results in NullObject if default value is applied

2020-06-21 Thread Remko Popma (Jira)


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

Remko Popma commented on GROOVY-9599:
-

Fix and additional test committed to the 
[master|https://github.com/apache/groovy/commit/16a5c42e53c440d3675d7b7cb91113a584663b86],
 
[GROOVY_3_0_X|https://github.com/apache/groovy/commit/829b19c7bcc91b3aa80f16379f980dc5dcdf9c64]
 and 
[GROOVY_2_5_X|https://github.com/apache/groovy/commit/ede7ffca2bf151471cfc888ee41d4c4f68d3d906]
 branches.

Test results look good in [CI|https://groovy.apache.org/buildstatus.html] 
([master|https://ci.groovy-lang.org/viewLog.html?buildId=2154=MasterTestJdk8],
  
[3.0|https://ci.groovy-lang.org/viewLog.html?buildId=2151=Groovy30xTestAllJdk8],
 
[2.5|https://ci.groovy-lang.org/viewLog.html?buildId=2159=Groovy25xCheckJdk8])

Resolving this ticket as fixed.

> CliBuilder: Option with "type: String, defaultValue ''" (empty String) 
> results in NullObject if default value is applied
> 
>
> Key: GROOVY-9599
> URL: https://issues.apache.org/jira/browse/GROOVY-9599
> Project: Groovy
>  Issue Type: Bug
>  Components: command line processing
>Affects Versions: 2.5.11, 3.0.4
>Reporter: Remko Popma
>Assignee: Remko Popma
>Priority: Major
> Fix For: 3.0.5, 2.5.13
>
>
> This is a follow-up ticket for GROOVY-9519:
> After checking with Groovy 3.0.4, it seems that only the "Integer with 
> defaultValue '0'" case was fixed, but not "String with defaultValue ''". The 
> latter became even worse. It still ignores the defaultValue, but instead of 
> creating a Boolean, it now creates a NullObject. Try this code:
> {code:java}
> @Grab('info.picocli:picocli-groovy:4.3.2')
> @GrabConfig(systemClassLoader=true)
> import groovy.cli.picocli.CliBuilder
> def cli = new CliBuilder(name: 'cliTest.groovy', stopAtNonOption: false)
> cli.h(type: Boolean, longOpt: 'help', usageHelp: true, required: false, 'Show 
> usage information')
> cli.a(type: String, longOpt: 'optA', required: false, args: 1, defaultValue: 
> '', 'Option a (optional)')
> def opts = cli.parse(args)
> opts || System.exit(1)
> if(opts.h) {
>   cli.usage()
>   System.exit(0)
> }
> println(opts.a.getClass())
> if (opts.a) {
>   println(opts.a)
> }
> {code}
> with Groovy 3.0.2:
> {code:java}
> % ~/tmp/groovy-3.0.2/bin/groovy ./cliTest.groovy
> class java.lang.Boolean
> {code}
> and with Groovy 3.0.4:
> {code:java}
> % ~/tmp/groovy-3.0.4/bin/groovy ./cliTest.groovy
> class org.codehaus.groovy.runtime.NullObject
> {code}



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


[jira] [Updated] (GROOVY-9599) CliBuilder: Option with "type: String, defaultValue ''" (empty String) results in NullObject if default value is applied

2020-06-21 Thread Remko Popma (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-9599?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Remko Popma updated GROOVY-9599:

Affects Version/s: 2.5.11

> CliBuilder: Option with "type: String, defaultValue ''" (empty String) 
> results in NullObject if default value is applied
> 
>
> Key: GROOVY-9599
> URL: https://issues.apache.org/jira/browse/GROOVY-9599
> Project: Groovy
>  Issue Type: Bug
>  Components: command line processing
>Affects Versions: 2.5.11, 3.0.4
>Reporter: Remko Popma
>Assignee: Remko Popma
>Priority: Major
> Fix For: 3.0.5
>
>
> This is a follow-up ticket for GROOVY-9519:
> After checking with Groovy 3.0.4, it seems that only the "Integer with 
> defaultValue '0'" case was fixed, but not "String with defaultValue ''". The 
> latter became even worse. It still ignores the defaultValue, but instead of 
> creating a Boolean, it now creates a NullObject. Try this code:
> {code:java}
> @Grab('info.picocli:picocli-groovy:4.3.2')
> @GrabConfig(systemClassLoader=true)
> import groovy.cli.picocli.CliBuilder
> def cli = new CliBuilder(name: 'cliTest.groovy', stopAtNonOption: false)
> cli.h(type: Boolean, longOpt: 'help', usageHelp: true, required: false, 'Show 
> usage information')
> cli.a(type: String, longOpt: 'optA', required: false, args: 1, defaultValue: 
> '', 'Option a (optional)')
> def opts = cli.parse(args)
> opts || System.exit(1)
> if(opts.h) {
>   cli.usage()
>   System.exit(0)
> }
> println(opts.a.getClass())
> if (opts.a) {
>   println(opts.a)
> }
> {code}
> with Groovy 3.0.2:
> {code:java}
> % ~/tmp/groovy-3.0.2/bin/groovy ./cliTest.groovy
> class java.lang.Boolean
> {code}
> and with Groovy 3.0.4:
> {code:java}
> % ~/tmp/groovy-3.0.4/bin/groovy ./cliTest.groovy
> class org.codehaus.groovy.runtime.NullObject
> {code}



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


[jira] [Updated] (GROOVY-9599) CliBuilder: Option with "type: String, defaultValue ''" (empty String) results in NullObject if default value is applied

2020-06-21 Thread Remko Popma (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-9599?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Remko Popma updated GROOVY-9599:

Fix Version/s: 2.5.13

> CliBuilder: Option with "type: String, defaultValue ''" (empty String) 
> results in NullObject if default value is applied
> 
>
> Key: GROOVY-9599
> URL: https://issues.apache.org/jira/browse/GROOVY-9599
> Project: Groovy
>  Issue Type: Bug
>  Components: command line processing
>Affects Versions: 2.5.11, 3.0.4
>Reporter: Remko Popma
>Assignee: Remko Popma
>Priority: Major
> Fix For: 3.0.5, 2.5.13
>
>
> This is a follow-up ticket for GROOVY-9519:
> After checking with Groovy 3.0.4, it seems that only the "Integer with 
> defaultValue '0'" case was fixed, but not "String with defaultValue ''". The 
> latter became even worse. It still ignores the defaultValue, but instead of 
> creating a Boolean, it now creates a NullObject. Try this code:
> {code:java}
> @Grab('info.picocli:picocli-groovy:4.3.2')
> @GrabConfig(systemClassLoader=true)
> import groovy.cli.picocli.CliBuilder
> def cli = new CliBuilder(name: 'cliTest.groovy', stopAtNonOption: false)
> cli.h(type: Boolean, longOpt: 'help', usageHelp: true, required: false, 'Show 
> usage information')
> cli.a(type: String, longOpt: 'optA', required: false, args: 1, defaultValue: 
> '', 'Option a (optional)')
> def opts = cli.parse(args)
> opts || System.exit(1)
> if(opts.h) {
>   cli.usage()
>   System.exit(0)
> }
> println(opts.a.getClass())
> if (opts.a) {
>   println(opts.a)
> }
> {code}
> with Groovy 3.0.2:
> {code:java}
> % ~/tmp/groovy-3.0.2/bin/groovy ./cliTest.groovy
> class java.lang.Boolean
> {code}
> and with Groovy 3.0.4:
> {code:java}
> % ~/tmp/groovy-3.0.4/bin/groovy ./cliTest.groovy
> class org.codehaus.groovy.runtime.NullObject
> {code}



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


[jira] [Commented] (GROOVY-9599) CliBuilder: Option with "type: String, defaultValue ''" (empty String) results in NullObject if default value is applied

2020-06-21 Thread Remko Popma (Jira)


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

Remko Popma commented on GROOVY-9599:
-

This turned out to have a separate, very different cause from GROOVY-9519.

Given code like this:
{code:java}
def cli = new CliBuilder()
cli.s(type: String, longOpt: 'str', required: false, args: 1, defaultValue: '', 
'description')
{code}
the {{groovy.cli.picocli.CliBuilder}} class constructs a 
{{picocli.CommandLine.Model.OptionSpec}} from the method arguments.

These method arguments are given to the conversion logic as a {{Map}}. During this conversion, there is the following conditional that 
prevents all options from getting an empty String value as their default value:
{code:java}
// Map m
if (!m.defaultValue) { //<-- (line 943) BAD: evaluates to false if value is 
empty String.
m.remove('defaultValue') // don't default the picocli model to empty string
}
{code}
This works fine when no default is specified, or when the default is specified 
as something that does not evaluate to {{false}} as per Groovy Truthiness, but 
when an empty String is intentionally specified as the default, what actually 
happens is that the default value becomes {{null}}.

The correct code should just look at the absence or presence of the 
"defaultValue" key in the map:
{code:java}
if (!m.containsKey('defaultValue')) { // GROOVY-9599
m.remove('defaultValue') // don't default the picocli model to empty string
}
{code}
I will commit a fix and an additional test soon.

> CliBuilder: Option with "type: String, defaultValue ''" (empty String) 
> results in NullObject if default value is applied
> 
>
> Key: GROOVY-9599
> URL: https://issues.apache.org/jira/browse/GROOVY-9599
> Project: Groovy
>  Issue Type: Bug
>  Components: command line processing
>Affects Versions: 3.0.4
>Reporter: Remko Popma
>Assignee: Remko Popma
>Priority: Major
> Fix For: 3.0.5
>
>
> This is a follow-up ticket for GROOVY-9519:
> After checking with Groovy 3.0.4, it seems that only the "Integer with 
> defaultValue '0'" case was fixed, but not "String with defaultValue ''". The 
> latter became even worse. It still ignores the defaultValue, but instead of 
> creating a Boolean, it now creates a NullObject. Try this code:
> {code:java}
> @Grab('info.picocli:picocli-groovy:4.3.2')
> @GrabConfig(systemClassLoader=true)
> import groovy.cli.picocli.CliBuilder
> def cli = new CliBuilder(name: 'cliTest.groovy', stopAtNonOption: false)
> cli.h(type: Boolean, longOpt: 'help', usageHelp: true, required: false, 'Show 
> usage information')
> cli.a(type: String, longOpt: 'optA', required: false, args: 1, defaultValue: 
> '', 'Option a (optional)')
> def opts = cli.parse(args)
> opts || System.exit(1)
> if(opts.h) {
>   cli.usage()
>   System.exit(0)
> }
> println(opts.a.getClass())
> if (opts.a) {
>   println(opts.a)
> }
> {code}
> with Groovy 3.0.2:
> {code:java}
> % ~/tmp/groovy-3.0.2/bin/groovy ./cliTest.groovy
> class java.lang.Boolean
> {code}
> and with Groovy 3.0.4:
> {code:java}
> % ~/tmp/groovy-3.0.4/bin/groovy ./cliTest.groovy
> class org.codehaus.groovy.runtime.NullObject
> {code}



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


[jira] [Resolved] (GROOVY-9592) Replace "groovy.generate.stub.in.memory" with "groovy.mem.stub"

2020-06-21 Thread Daniel Sun (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-9592?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Daniel Sun resolved GROOVY-9592.

Resolution: Fixed

> Replace "groovy.generate.stub.in.memory" with "groovy.mem.stub"
> ---
>
> Key: GROOVY-9592
> URL: https://issues.apache.org/jira/browse/GROOVY-9592
> Project: Groovy
>  Issue Type: Improvement
>Reporter: Daniel Sun
>Assignee: Daniel Sun
>Priority: Major
> Fix For: 4.0.0-alpha-1, 3.0.5
>
>  Time Spent: 1h 10m
>  Remaining Estimate: 0h
>
> The JVM option {{groovy.generate.stub.in.memory}} is too long for users to 
> remember, replace it with {{groovy.mem.stub}}
> For Groovy 3, {{groovy.generate.stub.in.memory}} will be deprecated.
> Since Groovy 4, {{groovy.generate.stub.in.memory}} will be removed.



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


[GitHub] [groovy] danielsun1106 merged pull request #1278: GROOVY-9592: Replace "groovy.generate.stub.in.memory" with "groovy.me…

2020-06-21 Thread GitBox


danielsun1106 merged pull request #1278:
URL: https://github.com/apache/groovy/pull/1278


   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [groovy] danielsun1106 commented on pull request #1269: GROOVY-7971: do not save instanceof types under logical or

2020-06-21 Thread GitBox


danielsun1106 commented on pull request #1269:
URL: https://github.com/apache/groovy/pull/1269#issuecomment-647197753


   @paulk-asert Any further comments on the PR?



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[jira] [Resolved] (GROOVY-8100) MarkupBuilder cant yield before first tag

2020-06-21 Thread Daniel Sun (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-8100?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Daniel Sun resolved GROOVY-8100.

Fix Version/s: 3.0.5
   4.0.0-alpha-1
 Assignee: Daniel Sun
   Resolution: Fixed

The proposed PR has been merged. Thanks for your contribution!

> MarkupBuilder cant yield before first tag
> -
>
> Key: GROOVY-8100
> URL: https://issues.apache.org/jira/browse/GROOVY-8100
> Project: Groovy
>  Issue Type: Bug
>  Components: XML Processing
>Affects Versions: 2.4.8, 3.0.0-rc-2
> Environment: Oracle Java 1.8.0_112, Windows 10 x64
>Reporter: Jochen Eddelbuettel
>Assignee: Daniel Sun
>Priority: Major
> Fix For: 4.0.0-alpha-1, 3.0.5
>
>  Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> Trying to produce an HTML5 compliant !DOCTYPE before starting with the 
> HTML-Elements. Without setting the private field 'state' to 2, the output 
> does not show the yielded output. 
> {code}
> def html = new groovy.xml.MarkupBuilder(new PrintWriter(System.out))
> //html.state = 2
> html.mkp.yieldUnescaped("\n")
> html.h1("Header")
> {code}
> I suggest fixing this by changing the yield-Method to not check the state 
> before doing the output, so that we see some output when the initial state is 
> still 0:
> {code}
> void yield(String value, boolean escaping) {
> if (state == 1) {
> state = 2;
> this.nodeIsEmpty = false;
> out.print(">");
> }
> // -- remove -- if (state == 2 || state == 3) {
> out.print(escaping ? escapeElementContent(value) : value);
> // -- remove -- }
> }
> {code}



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


[GitHub] [groovy] danielsun1106 commented on pull request #1284: [GROOVY-8100] MarkupBuilder - yield before any markup (state == 0)

2020-06-21 Thread GitBox


danielsun1106 commented on pull request #1284:
URL: https://github.com/apache/groovy/pull/1284#issuecomment-647197082


   Merged. Thanks.



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [groovy] danielsun1106 merged pull request #1284: [GROOVY-8100] MarkupBuilder - yield before any markup (state == 0)

2020-06-21 Thread GitBox


danielsun1106 merged pull request #1284:
URL: https://github.com/apache/groovy/pull/1284


   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[jira] [Resolved] (GROOVY-9344) CCE in closure shared variable assignment

2020-06-21 Thread Daniel Sun (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-9344?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Daniel Sun resolved GROOVY-9344.

Fix Version/s: 3.0.5
   4.0.0-alpha-1
   Resolution: Fixed

> CCE in closure shared variable assignment
> -
>
> Key: GROOVY-9344
> URL: https://issues.apache.org/jira/browse/GROOVY-9344
> Project: Groovy
>  Issue Type: Bug
>  Components: Static compilation, Static Type Checker
>Affects Versions: 2.5.8
>Reporter: Daniil Ovchinnikov
>Assignee: Eric Milles
>Priority: Major
> Fix For: 4.0.0-alpha-1, 3.0.5
>
>  Time Spent: 1h
>  Remaining Estimate: 0h
>
> {code}
> class A {}
> class B {}
> @groovy.transform.CompileStatic
> def cs() {
> def var
> var = new A()
> def c = {
> var = new B() // Cannot cast object 'B@4e234c52' with class 'B' to 
> class 'A'
> }
> c()
> var.toString()
> }
> assert cs() != null
> {code}



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


[jira] [Resolved] (GROOVY-9516) Static compiler infers wrong type for implicitly shared variables

2020-06-21 Thread Daniel Sun (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-9516?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Daniel Sun resolved GROOVY-9516.

Fix Version/s: 3.0.5
   4.0.0-alpha-1
   Resolution: Fixed

> Static compiler infers wrong type for implicitly shared variables
> -
>
> Key: GROOVY-9516
> URL: https://issues.apache.org/jira/browse/GROOVY-9516
> Project: Groovy
>  Issue Type: Bug
>  Components: Static compilation
>Affects Versions: 3.0.0, 2.5.11
>Reporter: Konstantin Nisht
>Assignee: Eric Milles
>Priority: Major
> Fix For: 4.0.0-alpha-1, 3.0.5
>
>
> Consider the following code
> {code:groovy}
> class A {}
> class B extends A{ def b() {}}
> class C extends A{}
> @CompileStatic
> static foo() {
>   def x = new B()
>   ({ x = new C() })()
>   def z = x
>   z.b()
> }
> {code}
> Here type of {{z}} in the last line of the method is deduced to be {{B}}. 
> Attempt to execute {{z.b()}} leads to cast exception, which is unexpected 
> under static compilation.



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


[GitHub] [groovy] danielsun1106 commented on pull request #1279: GROOVY-9344, GROOVY-9516: track shared variable assignment in closure like conditional branch

2020-06-21 Thread GitBox


danielsun1106 commented on pull request #1279:
URL: https://github.com/apache/groovy/pull/1279#issuecomment-647196334


   Merged. Thanks.



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [groovy] danielsun1106 merged pull request #1279: GROOVY-9344, GROOVY-9516: track shared variable assignment in closure like conditional branch

2020-06-21 Thread GitBox


danielsun1106 merged pull request #1279:
URL: https://github.com/apache/groovy/pull/1279


   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[jira] [Resolved] (GROOVY-9591) Compiler error for use of variable expression within tap closure

2020-06-21 Thread Daniel Sun (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-9591?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Daniel Sun resolved GROOVY-9591.

Fix Version/s: 3.0.5
   4.0.0-alpha-1
   Resolution: Fixed

> Compiler error for use of variable expression within tap closure
> 
>
> Key: GROOVY-9591
> URL: https://issues.apache.org/jira/browse/GROOVY-9591
> Project: Groovy
>  Issue Type: Bug
>Affects Versions: 3.0.4, 2.5.12
>Reporter: Eric Milles
>Assignee: Eric Milles
>Priority: Major
> Fix For: 4.0.0-alpha-1, 3.0.5
>
>  Time Spent: 20m
>  Remaining Estimate: 0h
>
> Consider the following:
> {code:groovy}
> @groovy.transform.ToString
> class A {
>   A(a) {}
>   def b
> }
> class C {
>   C() {
> this(new A(null).tap { b = 42 })
>   }
> C(x) {
> print x
>   }
> }
> new C() // should output "A(42)"
> {code}
> A has no default constructor, so properties are initialized in tap closure.  
> Because the "tap" expression is passed as argument to special constructor 
> call, extra static checking is performed and the error "Apparent variable 'b' 
> was found in a static scope but doesn't refer to a local variable, static 
> field or class." is emitted.
> Creation of A cannot be moved to a local variable because special constructor 
> call must be the first statement/expression in the constructor body.
> This was discovered while investigating variations of GROOVY-8327, 
> GROOVY-8389, and GROOVY-9587. 



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


[GitHub] [groovy] danielsun1106 commented on pull request #1276: GROOVY-9591: no error for dynamic variable in closure in static context

2020-06-21 Thread GitBox


danielsun1106 commented on pull request #1276:
URL: https://github.com/apache/groovy/pull/1276#issuecomment-647196217


   Merged. Thanks.



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [groovy] danielsun1106 merged pull request #1276: GROOVY-9591: no error for dynamic variable in closure in static context

2020-06-21 Thread GitBox


danielsun1106 merged pull request #1276:
URL: https://github.com/apache/groovy/pull/1276


   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[jira] [Created] (GROOVY-9605) leftShift operator does not work on BigInteger (throws UnsupportedOperationException)

2020-06-21 Thread Bertrand Martin (Jira)
Bertrand Martin created GROOVY-9605:
---

 Summary: leftShift operator does not work on BigInteger (throws 
UnsupportedOperationException)
 Key: GROOVY-9605
 URL: https://issues.apache.org/jira/browse/GROOVY-9605
 Project: Groovy
  Issue Type: Bug
  Components: groovy-jdk
Affects Versions: 3.0.4
 Environment: Groovy 3.0.4 Windows and Linux
Reporter: Bertrand Martin


h1. Problem
The _leftShift_ operator ({{<<}}) does not work on *BigInteger* (see 
[StackOverflow 
question|https://stackoverflow.com/questions/62496971/leftshift-method-on-biginteger-in-groovy]).

The *leftShift()* method is however described in [Groovy's JDK 
enhancements|http://docs.groovy-lang.org/latest/html/api/org/codehaus/groovy/runtime/DefaultGroovyMethods.html#leftShift(java.lang.Number,java.lang.Number)].

The below code fails with Groovy 3.0.4:
{code:groovy}
Integer i = new Integer(3)
assert 12 == i << 2

Number b = new BigInteger("3")
assert 12 == b << 2
{code}

It throws an exception:
{noformat}
Caught: java.lang.UnsupportedOperationException: Cannot use leftShift() on this 
number type: java.math.BigInteger with value: 3
java.lang.UnsupportedOperationException: Cannot use leftShift() on this number 
type: java.math.BigInteger with value: 3
at test.run(test.groovy:5)
{noformat}

Consequence: you cannot use the {{<<}} operator on a _Number_ if this number is 
a _BigInteger_.

h1. Understanding of the problem
(I'm not familiar with the code)
The 
[BigIntegerMath|https://github.com/groovy/groovy-core/blob/master/src/main/org/codehaus/groovy/runtime/typehandling/BigIntegerMath.java]
 class does not implement the _leftShift()_ method.

Also, please note that JDK's 
[BigInteger|https://docs.oracle.com/javase/8/docs/api/java/math/BigInteger.html#shiftLeft-int-]
 method for this operation is *not* _leftShift()_ but _shiftLeft()_!

h1. Workaround
Using mixins, the below code works:
{code:groovy}
class EnhancedNumber {

static def originalLeftShift = 
org.codehaus.groovy.runtime.DefaultGroovyMethods.
static Number leftShift(Number self, Number operand) {
self.class == BigInteger ? self.shiftLeft(operand) : 
originalLeftShift(self, operand)
}
}

Number.mixin(EnhancedNumber)

Integer i = new Integer(3)
assert 12 == i << 2

Number b = new BigInteger("3")
assert 12 == b << 2
{code}



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


[GitHub] [groovy] eric-milles opened a new pull request #1285: GROOVY-9604: STC: add support for accessing additional closure methods and properties

2020-06-21 Thread GitBox


eric-milles opened a new pull request #1285:
URL: https://github.com/apache/groovy/pull/1285


   https://issues.apache.org/jira/browse/GROOVY-9604



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[jira] [Created] (GROOVY-9604) STC: method or property missing errors for Closure's getResolveStrategy(), etc.

2020-06-21 Thread Eric Milles (Jira)
Eric Milles created GROOVY-9604:
---

 Summary: STC: method or property missing errors for Closure's 
getResolveStrategy(), etc.
 Key: GROOVY-9604
 URL: https://issues.apache.org/jira/browse/GROOVY-9604
 Project: Groovy
  Issue Type: Bug
Reporter: Eric Milles
Assignee: Eric Milles


Consider the following:
{code:groovy}
@groovy.transform.CompileStatic
class C {
  void m() {
{ ->
  getResolveStrategy() // and other Closure methods/properties except 
"owner", "delegate" and "thisObject"
}()
  }
}
{code}

Trying to access the enclosing closure's metadata results in STC compiler 
errors.



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


[jira] [Commented] (GROOVY-8845) @DelegatesTo works only for the first vararg

2020-06-21 Thread Eric Milles (Jira)


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

Eric Milles commented on GROOVY-8845:
-

GROOVY-6022 seems to suggest that a compiler error should be emitted for 
@DelegatesTo applied to array (aka varargs parameter).

> @DelegatesTo works only for the first vararg
> 
>
> Key: GROOVY-8845
> URL: https://issues.apache.org/jira/browse/GROOVY-8845
> Project: Groovy
>  Issue Type: Bug
>  Components: Static Type Checker
>Affects Versions: 2.5.3
>Reporter: Daniil Ovchinnikov
>Priority: Major
>
> {code:groovy}
> def md(@DelegatesTo.Target Object target, @DelegatesTo(strategy = 
> Closure.DELEGATE_FIRST) Closure... arg) {
> for (Closure a : arg) {
> a.delegate = target
> a.resolveStrategy = Closure.DELEGATE_FIRST
> a()
> }
> }
> class D {
>   def foo() { 42 }
> }
> @groovy.transform.CompileStatic
> def test() {
> md(
>   new D(), 
>   { print(foo()) }, 
> //  { print(foo()) }, // [Static type checking] - Cannot find matching 
> method ConsoleScript15#foo()
> //  { print(foo()) }, // [Static type checking] - Cannot find matching 
> method ConsoleScript15#foo()
> )
> }
> test()
> {code}



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