Closed wadoon closed 2 years ago
I can see some merit in the idea of a companion object named \spec, although I don't particularly like having to use a name like \spec in an otherwise Java-like name. Would it be sensible to have the name "spec" used for this in JML with the provision that \spec could also be used as an alias, in case the Java code uses "spec"?
I summarize this proposal as the following
\spec.
can be used to designate that only specification names should be considered.However, in retrospect I don't think a solution is needed here at all. Casting works just fine. The following pure Java example would work for JML as well.
class Parent {
int n = 10;
}
class Parent2 extends Parent {
int n = 20;
}
public class Names extends Parent2 {
int n = 30;
public static void main(String ... args) {
Names x = new Names();
System.out.println(x.n + " " + ((Parent2)x).n + " " + ((Parent)x).n); // yields 30 20 10
}
}
So I propose adding no new features to JML to refer to hidden names.
Yes, if we can just use casting, then we could just explain that in the reference manual and not add new features to JML. Good idea @davidcok!
To be clear, I'm okay with the proposal as in @davidcok's last long message, without any new JML features.
I am happy if we can get away without a new construct.
From the last Chapter 4 draft in #6. We have an open discussion point around the name conflicts.
I re-post here my proposal for the
\spec
namespace.For the ambiguity problem, the
\jml(n)
would not my favorite. This is very untypical for Java.super.Parent.n
is also strange as Java definesParent.super.n
(in alignment toOuterClass.this.n
).My suggestion would be to have a concept like an companion object (similar to Kotlin). Every instance has a companion instance, a field of a generated inner class called
\spec
, which holds all JML member definitions.If we write
abc
inside a JML construct, first, we lookup with the Java name resolution, if not found we lookup in the\spec
namespace. It also can be fully-qualified address by usingsuper.\spec.n
, orthis.\spec.n
. It is also usable for static specification:java.lang.Object.\spec.method()
. Additionally, it makes easy to explainspec_public
& Co. These defines the visibility of the elements in\spec
.The construct would looks similar on an idealized view: