Reputation: 123
I have an Alloy specification to represent a subset of java programming language. Below we have some part of this model:
abstract sig Type {}
one sig void_ extends Type {}
abstract sig PrimitiveType extends Type {}
one sig Int_, Long_ extends PrimitiveType {}
sig Method {
id : one MethodId,
param: lone Type,
acc: lone Accessibility,
return: one Type,
b: one Body
}{
(return=void_) => (
( (b=ConstructorMethodInvocation) => (b.cmethodInvoked).return = void_) ||
( (b=MethodInvocation) => ((b.id_methodInvoked).return = void_) )
)
}
abstract sig Body {}
sig MethodInvocation extends Body {
id_methodInvoked : one Method,
q: lone Qualifier
}
sig ConstructorMethodInvocation extends Body {
id_Class : one Class,
cmethodInvoked: one Method
}{
[email protected] != private_
this.@cmethodInvoked in ((this.@id_Class).*extend).methods
}
In this code, there is a type error in Method signature, that is:
This cannot be a legal relational join where
left hand side is this . (this/Method <: b) .
(this/ConstructorMethodInvocation <: cmethodInvoked) (type =
{this/Method})
right hand side is this . (this/Method <: return) (type =
{this/Type})
And i am not understanding why.
Thanks in advance,
Upvotes: 0
Views: 178
Reputation: 3496
The problem is that "return" is implicitely scoped and thus represents the result of "this.return", i.e. "return" is already a "Type", not a relation from "Method" to "Type".
A possible solution is to avoid the implicit scoping by using a separate "fact" section and explicitly quantify over all "Methods":
fact {
all m: Method | (m.return = void_ .....
}
Upvotes: 1