[Grace-core] [less important] Abstract methods and classes & Annotations

James Noble kjx at ecs.vuw.ac.nz
Fri Mar 8 23:08:09 PST 2013


We should add an "abstract" annotation.  

A method that "is abstract" throws a dynamic error if called.
   (option: it should also have an empty body, note that we 
    can't really get rid of the body altogether...)

An object constructor / class that "is abstract" throws a dynamic
 error if called **as a normal message request**, but not as a
 **factory message request**.

Optionally, could throw errors or warnings if you define a class or
object constructor with an abstract method that is not itself
abstract.

The standard static checker should raise static warnings about
abstract.


Implementation Note:

We have the same annotation now for methods & objects.  That won't do
in general, they'll need to be different somehow if they are to be
more than special cases. Stolen blatantly from Ceylon (and Java I
guess) annotations must work something like this.

an annotation is a method (on what object?  the dialect?) that returns
an annotation object.  Annotation methods can take parameters etc so
you can do things like this:

class Foo 
  is invariant { a == b }   { 
    var a is deprecated("stupid, should be b") 
    var b 
    method c is
      require { b = 10 }, 
      ensure  { a = 12 }
      { ... }
}

minor point: separate annotations with ","?  or ";" and allow
newlines to elide?  or "," and allow newlines to elide?

annotation method returns an annotation *object* that somehow gets
attached to the AST.    But a some point there must be some
double-dispatch that goes on (AST node calls into their annotations)
or pattern matching or something to create actually annotation
meta-objects that will get attached to the underlying objects
(not AST nodes)   so that e.g. an abstract-class-metaobject
is different to an abstract-method-metaobject...

Hopefully types can be (over)used to control where annotations may
apply (again like Java/Ceylon)...







More information about the Grace-core mailing list