Types 合金中的类型错误

Types 合金中的类型错误,types,alloy,Types,Alloy,我有一个合金规范来表示java编程语言的子集。下面是该模型的一些部分: 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 Typ

我有一个合金规范来表示java编程语言的子集。下面是该模型的一些部分:

  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
    }
在此代码中,方法签名中存在一个类型错误,即:

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})
这不能是合法的关系联接,其中
左手边是这个。(this/Method问题在于“return”是隐式作用域,因此表示“this.return”的结果,即“return”已经是一个“类型”,而不是“Method”到“Type”的关系

一种可能的解决方案是通过使用单独的“事实”部分并明确量化所有“方法”来避免隐式范围界定:


谢谢你的回答,wmeyer,但我不明白为什么return不是“Method”的关系,为什么“return”是隐式作用域?你能告诉我更多细节吗?“return”是隐式作用域,因为它是在签名事实中使用的。请参阅Alloy 3.0参考手册(可以在Google上找到)。引用:“与任何其他事实一样,签名事实是始终保持不变的约束。然而,与其他事实不同,签名事实在签名集上是隐式量化的。给定签名声明
sig S{…}{F}
签名事实F被解释为好像一个人写了一个显式事实
fact{all this:S{F}”
好的,再次感谢您的澄清,wmeyer,但我仍然不明白的是:为什么在签名事实中不能使用return(作为方法签名的有效关系)?
fact {
  all m: Method | (m.return = void_ .....
}