groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thibault Kruse <tibokr...@googlemail.com>
Subject Re: Properties and multi-getters
Date Fri, 21 Aug 2015 18:21:08 GMT
would the compiler then refuse to compile a class having this, or
merely refuse to resolve the shorthand access "foo.wildcard" if that
is ambiguous (requiring the developer to choose by explicitly invoking
the desired method)? In the latter case, a compiler error (or runtime
exception) seems okay to me.
Compiler error just for defining a class with silly methods should IMO
not be a compiler error.

On Fri, Aug 21, 2015 at 8:11 PM, Cédric Champeau
<cedric.champeau@gmail.com> wrote:
> Just to make it clear: the compile time error that I am suggesting is when
> you mix static and non static versions of the same property.
>
> 2015-08-21 20:07 GMT+02:00 Thibault Kruse <tibokruse@googlemail.com>:
>>
>> JavaBeans specification is to use "is" version first (for boolean
>> fields only), so +1 on Groovy adhering to that.
>> +1 to have consistent behavior.
>>
>> Compile time error seems a bit harsh. But maybe codenarc could raise
>> this as code smell in any case.
>>
>> On Fri, Aug 21, 2015 at 5:35 PM, Cédric Champeau
>> <cedric.champeau@gmail.com> wrote:
>> > Hi guys,
>> >
>> > While migrating Gradle to Groovy 2.4.4, I spent several hours debugging
>> > an
>> > integration test that mysteriously failed under 2.4.4. It took me a lot
>> > of
>> > time to figure out that the offending line was this one:
>> >
>> >
>> > https://github.com/gradle/gradle/blob/9d9798019a47aaf034cdb85a931eb8fefdd4060f/subprojects/launcher/src/integTest/groovy/org/gradle/launcher/daemon/testing/DaemonsState.groovy#L44
>> >
>> > In Groovy 2.3, `wildcard` called `isWildcard`. Since we added support
>> > for
>> > multiple setters (I think it is related, but not 100% sure), the
>> > behavior
>> > seem to have changed: now Groovy calls `getWildcard`.
>> >
>> > But as you can see, there's a culprit: `getWildcard` is a static method,
>> > while `isWildcard` is an instance one. How silly!
>> >
>> > I think this should be a compile time error (having both a static `get`
>> > method and an instance `is` one, and the reverse).
>> >
>> > It shouldn't be a problem to have both static or both instance methods,
>> > as
>> > long as the behavior is deterministic. That is, if you find both:
>> >
>> > boolean getA()
>> > boolean isA()
>> >
>> > and that you access the property using:
>> >
>> > foo.a
>> >
>> > It should *always* be the same method which is called. My preference
>> > would
>> > go with the "is" version first, but I'm not sure we make any guarantee
>> > on
>> > this.
>> >
>> > WDYT?
>
>

Mime
View raw message