groovy

Optional interface modifier

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0-JSR-6
  • Fix Version/s: 1.5.2
  • Labels:
    None
  • Environment:
    Win XP
  • Number of attachments :
    2

Description

The optional modifier on an interface declaration is prepared to accept ANY Groovy modifier including private, static, transient, etc.

Activity

Hide
Paul King added a comment -

transient and static are definitely bugs but private should be OK shouldn't it?

Show
Paul King added a comment - transient and static are definitely bugs but private should be OK shouldn't it?
Hide
Andres Almiray added a comment -

Looks like only 'final' and 'transient' are detected at compile time. 'abstract','static' and 'synchronized' are allowed but those modifiers are meaningless IMO. On top level interfaces there is no point in declaring an access modifier other than public but it does on inner interfaces (not yet supported) so using protected/private on them should at least give a warning for the time being?

bash-3.2$ groovyc AI.groovy
bash-3.2$ groovyc FI.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed,
FI.groovy: 1: The interface 'FI' must not be final. It is by definition abstract
.
 @ line 1, column 7.
   final interface FI {}
         ^

1 error

bash-3.2$ groovyc SI.groovy
bash-3.2$ groovyc TI.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed,
TI.groovy: 1: The interface 'TI' has an incorrect modifier transient.
 @ line 1, column 11.
   transient interface TI {}
             ^

1 error

bash-3.2$ groovyc YI.groovy
bash-3.2$
Show
Andres Almiray added a comment - Looks like only 'final' and 'transient' are detected at compile time. 'abstract','static' and 'synchronized' are allowed but those modifiers are meaningless IMO. On top level interfaces there is no point in declaring an access modifier other than public but it does on inner interfaces (not yet supported) so using protected/private on them should at least give a warning for the time being?
bash-3.2$ groovyc AI.groovy
bash-3.2$ groovyc FI.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed,
FI.groovy: 1: The interface 'FI' must not be final. It is by definition abstract
.
 @ line 1, column 7.
   final interface FI {}
         ^

1 error

bash-3.2$ groovyc SI.groovy
bash-3.2$ groovyc TI.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed,
TI.groovy: 1: The interface 'TI' has an incorrect modifier transient.
 @ line 1, column 11.
   transient interface TI {}
             ^

1 error

bash-3.2$ groovyc YI.groovy
bash-3.2$
Hide
Paul King added a comment -

Added 'native' to the list of detected and ruled out modifiers. I attempted to add 'synchronized' but one of the tests fails. Soem of our intermediate generated classes may accidentally have this bit set. I think we can add this back in once we work out where this is occurring. For reference, the script below fails with the error message shown when trying to compile if I add the synchronized check in, so it is commented out at the moment:

Script:

interface A {
    def foo = 1
}
class B implements A {
    def foo() {foo}
}
assert new B().foo() == 1

Error:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, C:\testScript.groovy: -1: The class 'A$1' has an incorrect modifier synchronized.
 @ line -1, column -1.
1 error
Show
Paul King added a comment - Added 'native' to the list of detected and ruled out modifiers. I attempted to add 'synchronized' but one of the tests fails. Soem of our intermediate generated classes may accidentally have this bit set. I think we can add this back in once we work out where this is occurring. For reference, the script below fails with the error message shown when trying to compile if I add the synchronized check in, so it is commented out at the moment: Script:
interface A {
    def foo = 1
}
class B implements A {
    def foo() {foo}
}
assert new B().foo() == 1
Error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, C:\testScript.groovy: -1: The class 'A$1' has an incorrect modifier synchronized.
 @ line -1, column -1.
1 error
Hide
Paul King added a comment -

OK, synchronized is added to. That just about wraps up the essential items for this issue. There are other unused modifiers at the moment but they are happily ignored and if we end up supporting inner classes, then they will all come into play.

I did notice however that you can have invalid modifiers in interface methods. So, I'll add that in and then I think we can close this issue. Here is what you can currently have:

interface Foo {
   def strictfp /*native*/ volatile synchronized doit( String param, int o )
}

If you use native Java complains. Groovy happily ignores the other values even though they never make sense here.

Show
Paul King added a comment - OK, synchronized is added to. That just about wraps up the essential items for this issue. There are other unused modifiers at the moment but they are happily ignored and if we end up supporting inner classes, then they will all come into play. I did notice however that you can have invalid modifiers in interface methods. So, I'll add that in and then I think we can close this issue. Here is what you can currently have:
interface Foo {
   def strictfp /*native*/ volatile synchronized doit( String param, int o )
}
If you use native Java complains. Groovy happily ignores the other values even though they never make sense here.
Hide
Paul King added a comment -

I think there are now error messages for all the obvious candidates. There are some which we don't deal with at the moment but hope to over time, e.g. a private Interface may make sense inside a Script ... one day. And we may support inner/nested classes/interfaces one day too.

Show
Paul King added a comment - I think there are now error messages for all the obvious candidates. There are some which we don't deal with at the moment but hope to over time, e.g. a private Interface may make sense inside a Script ... one day. And we may support inner/nested classes/interfaces one day too.
Hide
Paul King added a comment -

close off release 1.5.4

Show
Paul King added a comment - close off release 1.5.4

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: