奥斯陆错误“M0197:“文本”的解释 不能在类型上下文中使用”?

发布于 2024-07-08 17:10:41 字数 965 浏览 6 评论 0原文

在 Microsoft Oslo SDK CTP 2008(使用 Intellipad)中,以下代码可以正常编译:

module M {
    type T {
        Text : Text;
    }
}

编译以下代码时会导致错误“M0197:‘文本’不能在类型上下文中使用”,

module M {
    type T {
        Text : Text;
        Value : Text; // error
    } 
}

我看不到示例之间的区别,因为在第一种情况下,文本也用在类型上下文中。

更新:

为了增加混乱,请考虑以下示例,该示例也可以正常编译:

module M {
    type X;
    type T {
      X : X;
      Y : X;
    } 
}

M 语言规范指出:

字段声明会覆盖词法作用域,以防止声明的类型绑定到声明本身。 字段声明的归属类型不能是声明本身; 但是,该声明可以在约束中使用。 考虑以下示例:

A 型; B型{ 答:一个; }

字段声明 A 的类型归属的词法封闭范围是实体声明 B。无一例外,类型归属 A 会绑定到循环引用中的字段声明,这是一个错误。 在这种情况下,异常允许词法查找跳过字段声明。

似乎用户定义的类型和内置(固有)类型并没有被平等对待。

UPDATE2:

请注意,上面示例中的 Value 不是保留关键字。 如果将 Value 重命名为 Y,也会出现相同的错误。

有任何想法吗?

问候, 坦伯格

In Microsoft Oslo SDK CTP 2008 (using Intellipad) the following code compiles fine:

module M {
    type T {
        Text : Text;
    }
}

while compiling the below code leads to the error "M0197: 'Text' cannot be used in a Type context"

module M {
    type T {
        Text : Text;
        Value : Text; // error
    } 
}

I do not see the difference between the examples, as in the first case Text is also used in a Type context.

UPDATE:

To add to the confusion, consider the following example, which also compiles fine:

module M {
    type X;
    type T {
      X : X;
      Y : X;
    } 
}

The M Language Specification states that:

Field declarations override lexical scoping to prevent the type of a declaration binding to the declaration itself. The ascribed type of a field declaration must not be the declaration itself; however, the declaration may be used in a constraint. Consider the following example:

type A;
type B {
A : A;
}

The lexically enclosing scope for the type ascription of the field declaration A is the entity declaration B. With no exception, the type ascription A would bind to the field declaration in a circular reference which is an error. The exception allows lexical lookup to skip the field declaration in this case.

It seems that user defined types and built-in (intrinsic) types are not treated equal.

UPDATE2:

Note that Value in the above example is not a reserved keyword. The same error results if you rename Value to Y.

Any ideas?

Regards, tamberg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等风来 2024-07-15 17:10:41

据我所知,您重新定义了 Text:

Text : Text

然后您尝试将其用于 Value: 的类型,

Value : Text

这是不允许的。 为什么使用类型名称作为属性重新定义类型我并不完全清楚(仍在阅读 M 语言规范),但我确信这是有充分理由的。 只需将 Text 命名为尚未定义的类型(用方括号 ([Text]) 对其进行转义也不起作用)。

From what I am seeing you have redefined Text:

Text : Text

and then you are attempting to use it for the type of Value:

Value : Text

which is not allowed. Why using a type name as a property redefines a type I'm not entirely clear on (still reading M language specification), but I'm sure there's a good reason for it. Just name Text something that's not already a defined type (escaping it with brackets ([Text]) does not work either).

鹿童谣 2024-07-15 17:10:41

问题是:在 M 中,您可以执行如下操作:

module M
{
  type Address;
  type Person
  {
    Addresses : Address*;
    FavoriteAddress : Address where value in Addresses;
  }  
}

在该示例中,“Addresses”指的是 Person.Addresses。 那么,问题是,当您编写诸如

module M
{
  type T
  {
    Text : Text;
    SomethingElse : Text;
  }
}

...之类的无害内容时,SomethingElse 的类型归属中的“Text”不是指 Language.Text,而是指 T.Text。 这就是问题所在。 解决方法是这样写:(

module M
{
  type T
  {
    Text : Text;
    SomethingElse : Language.Text;
  }
}

您可能想知道为什么像“Text : Text”这样的东西在上面的示例中起作用。有一个特殊的规则:字段类型归属中的标识符不能引用字段本身。这个的规范示例是“地址:地址”。)

Here's the problem: in M, you can do tricks like this:

module M
{
  type Address;
  type Person
  {
    Addresses : Address*;
    FavoriteAddress : Address where value in Addresses;
  }  
}

In that example, "Addresses" refers to Person.Addresses. The problem, then, is that when you write something innocuous like

module M
{
  type T
  {
    Text : Text;
    SomethingElse : Text;
  }
}

...then the "Text" in the type ascription for SomethingElse refers not to Language.Text, but to T.Text. And that's what's going wrong. The workaround is to write it like this:

module M
{
  type T
  {
    Text : Text;
    SomethingElse : Language.Text;
  }
}

(You may wonder why things like "Text : Text" work in the example above. There's a special rule: identifiers in a field's type ascription cannot refer to the field itself. The canonical example for this is "Address : Address".)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文