[英]type error in Alloy
I have an Alloy specification to represent a subset of java programming language. 我有一个Alloy规范来表示Java编程语言的子集。 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
}{
this.@cmethodInvoked.acc != 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, 提前致谢,
The problem is that "return" is implicitely scoped and thus represents the result of "this.return", ie "return" is already a "Type", not a relation from "Method" to "Type". 问题在于“返回”是隐式范围的,因此代表“ this.return”的结果,即“返回”已经是“类型”,而不是从“方法”到“类型”的关系。
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_ .....
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.