tags:

views:

249

answers:

3

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

+1  A: 

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).

cfeduke
"Why using a type name as a property redefines a type I'm not entirely clear on" That's exactly my question. The semantics of the first example becomes hard to understand if the error in the second example is not a bug.
tamberg
Yes this is confusing though I think I'm on the verge of an "a ha!" moment.
cfeduke
+1  A: 

http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/fcaf10a1-52f9-4ab7-bef5-1ad9f9112948

tamberg
Link to the "Oslo" forum wich answers the question.
Lars Corneliussen
+1  A: 

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".)