Restricting list extensions

Saravanan Palanichamy <[email protected]>
Newsgroups gmane.comp.lang.groovy.user
Message-ID <CAG3fL7m6mv3MtfFgVa6BxJw8WvumbPuf6k1YjOzxYb7Qg1Qj4g@mail.gmail.com>
Hello Groovy users/devs

I have a derived class from List (lets call this MyImmutableList) and I
want to only allow the use of certain extension functions. For example,
collect is ok, but left shift is not

myImmutableList << 100 // I want to prevent this because its an immutable
list)
myImmutableList.collect { it + 1 } // This is ok

How do I achieve this? I have my own AST transformations and I can detect
the use of the MyImmutableList class. My first guess is

   - Enable Static compile
   - Post static compile, detect all extension methods and the object
   inferred_type it is called on. If type is MyImmutableList, check if
   extension method is allow listed. If not cause compile error

I am not sure if this is fool proof. Are there easier ways to do this? Is
it possible to get the static compile mechanism to tie unknown methods to a
default method that I can check for and just error on?

regards
Saravanan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.