Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script variables not recognised when compiler config added (regression) #1555

Closed
ssadedin opened this issue Mar 10, 2024 · 4 comments
Closed

Comments

@ssadedin
Copy link

In the past I could add a compiler configuration in the Groovy Compiler section of the project settings, and this would allow me to add type safe methods to my script, while also allowing for dynamic variables to be defined and work with type inferencing features.

In newer versions, when I define a custom compile config, I still get my custom type safe methods working, but scripts seem to lose the ability for dynamic variables to be defined : they are marked with an underline in the editor and autocomplete on their methods and properties no longer works.

Here are pictures of the two versions behaviour side by side:

. Version 4.8.0 Version 5.2.0
image image

If I remove the compiler configuration from the new version then its behaviour is the same as the old version. Only when I set a custom compiler configuration, now I get the problematic behaviour.

Apologies it is a bit complicated to create a complete reproducible test scenario for this, but let me know if you can't reproduce and I will take a shot at setting up a complete example.

@eric-milles
Copy link
Member

Can you describe your config script a bit (or include the whole thing)? Are you setting a script base class?

@ssadedin
Copy link
Author

Thanks for following up! And apologies that's an obvious thing to ask. The config script is super simple, the only thing it does is set a script base class. I've reproduced the issue in an isolated project now, so it is like this:

withConfig(configuration) {
    configuration.setScriptBaseClass('test.TestScriptBase')
}

And the base class itself is just a dummy one (the problem is what happens to things NOT in the base class, rather than any functionality it provides itself):

package test

class TestScriptBase extends Script {
    void foobar(String foo) {
    }
    public Object run() { // never invoked
        return null;
    }
}

I've bundled these into a zip file:

groovyc_example.zip

I've found it's always a bit dicey when you put the base class for the compiler into the same project as the code being compiled, but it does reproduce the problem here as long as I ensure it got compiled first and then modify the script afterwards.

Another thing I should have mentioned is that I'm using two different versions of Eclipse here. The older one is Eclipse-2022-12 while the newer one is Eclipse-2023-12.

Let me know any other useful info I could provide.

@ssadedin
Copy link
Author

I think I resolved this : closely reading the documentation for script base classes I can see that in fact you're not supposed to override the run() method but leave the class abstract. When I made the class abstract and remove the run method, then the type inferencing works and the underlines go away.

It's an odd thing that somehow this subtle mistake on my part worked in earlier versions but caused problems later on.

I'll leave this open in case you want to comment or feel like it's still worth addressing in some manner, but I think happy to call this my mistake.

Thanks for the consideration and sorry for the noise - hopefully helps someone in the future having this documented here.

@eric-milles
Copy link
Member

eric-milles commented Mar 12, 2024

You are allowed to overload the run() method, but you must then supply one abstract method that is called at some point in your run method. The single-abstract-method detection was updated for #1503 and this might be what caught you off guard.

The fix for GROOVY-8096 mas also be the cause: a51a8c0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants