groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jamie Echlin <jamie.ech...@gmail.com>
Subject Re: type checked with generics issue
Date Wed, 26 Aug 2015 14:19:30 GMT
Couldn't agree more, kudos to, I think, Cedric amongst others. It's the
gold standard for docn.

I have another related STC issue which I'd be grateful for some help on.

Given:

// def isThing = {s -> return false} // this is defined outside of the
script

isThing('foo')

How can I pass to the type-checking extension the class node for the
isThing closure? So far I have been generating these
with: GenericsUtils.makeClassSafeWithGenerics and ClassHelper.make.

I am unsure how to do this for closure, and closure
params. ClassHelper.make(Closure) is not working, I get:

[Static type checking] - Cannot find matching method Script14#isThing()

cheers, jamie


On Wed, Aug 26, 2015 at 1:32 PM, Winnebeck, Jason <
Jason.Winnebeck@windstream.com> wrote:

> Whoever wrote that type inference documentation should be commended, it is
> very good and very thorough. Very understandable and easy to read yet
> detailed enough even to satisfy the curiosity of “how did they get that to
> work?”. In fact, since moving out of Codehaus wiki, the documentation is
> far improved. From a user’s perspective I was concerned at first that a
> rewrite would take forever, but it didn’t and these new docs continue to
> impress each time I open them.
>
>
>
> Jason
>
>
>
> *From:* Cédric Champeau [mailto:cedric.champeau@gmail.com]
> *Sent:* Wednesday, August 26, 2015 4:19 AM
> *To:* users@groovy.incubator.apache.org
> *Subject:* Re: type checked with generics issue
>
>
>
> Hi Jamie,
>
>
>
> See
> http://docs.groovy-lang.org/latest/html/documentation/#_variables_vs_fields_in_type_inference
> for an explanation.
>
>
>
> 2015-08-26 10:14 GMT+02:00 Jamie Echlin <jamie.echlin@gmail.com>:
>
> I'm confused about the type checking in one instance. Take this:
>
>
>
> class Foo {
>
>     String getBar() { "bar" }
>
> }
>
>
>
> @TypeChecked
>
> class TestFoo {
>
>
>
>     def foo = new Foo()
>
>
>
>     void test() {
>
>         assert foo.bar == "bar"
>
>     }
>
> }
>
>
>
> If the def of foo is within the test() method it's fine, but where it is
> it seems not to be able to resolve the type (cannot resolve symbol "bar").
> Why can't it infer the type - I don't see what will change the type between
> initialisation and the when the method is called.
>
>
>
> cheers, jamie
>
>
>
>
> ------------------------------
> This email message and any attachments are for the sole use of the
> intended recipient(s). Any unauthorized review, use, disclosure or
> distribution is prohibited. If you are not the intended recipient, please
> contact the sender by reply email and destroy all copies of the original
> message and any attachments.
>

Mime
View raw message