Re: switch does not recognise Class?

2024-07-01 Thread Paul King
Sounds good. Let me know if you want to do a PR, or otherwise I'll make the change. Cheers, Paul. Virus-free.www.avast.com

Re: switch does not recognise Class?

2024-07-01 Thread o...@ocs.cz
Paul, thanks again! Possibly (I am not entirely sure, but what do you think?) it might be better if the switch explanation was somewhat re-formulated, something like “ Switch supports — among others — the following kinds of comparisons (see please [the isCase operator](link) for a full list):”

Re: switch does not recognise Class?

2024-06-30 Thread Paul King
The isCase operator is documented under operator overloading: https://docs.groovy-lang.org/latest/html/documentation/#_operator_overloading With further clarification here: https://docs.groovy-lang.org/latest/html/groovy-jdk/java/lang/Class.html#isCase(java.lang.Object) But yeah, it would be bett

Re: switch does not recognise Class?

2024-06-30 Thread OCsite
Paul, > On 30. 6. 2024, at 23:03, Paul King wrote: > For instances, instanceof is applied. For classes, isAssignableFrom is > applied. I see, thanks! Is that documented somewhere? Perhaps I'm just blind, but I can't see it here

Re: switch does not recognise Class?

2024-06-30 Thread Paul King
For instances, instanceof is applied. For classes, isAssignableFrom is applied. You can always check by looking at isCase. assert String.isCase('foo') assert !Class.isCase(String) assert CharSequence.isCase(String) assert Object.isCase(Class) assert switch(String) { case Class -> false c

Re: switch does not recognise Class?

2024-06-30 Thread OCsite
Christopher, > On 30. 6. 2024, at 22:42, Christopher Smith wrote: > You're comparing `class java.lang.String` and `class java.lang.Class`. > No, I'm not. > Which rule in the docs leads you to expect this to be truthy? > The very first documented one, namely Class case values match if the switc

Re: switch does not recognise Class?

2024-06-30 Thread Christopher Smith
You're comparing `class java.lang.String` and `class java.lang.Class`. Which rule in the docs leads you to expect this to be truthy? On Sun, Jun 30, 2024, 13:17 o...@ocs.cz wrote: > Hi there, > > is this the intended behaviour? > > === > groovy:000> switch (String) { case Class: println "C"; bre

switch does not recognise Class?

2024-06-30 Thread o...@ocs.cz
Hi there, is this the intended behaviour? === groovy:000> switch (String) { case Class: println "C"; break; case {it instanceof Class}: println "CC" } CC ===> null groovy:000> === Based on the switch documented semantic I would presume "C" should be printed out, not "CC"? Thanks and all the