Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specialized type tests #688

Open
tombentley opened this issue May 25, 2015 · 7 comments
Open

Specialized type tests #688

tombentley opened this issue May 25, 2015 · 7 comments

Comments

@tombentley
Copy link
Member

While working on serialization I've come across the need to know about the types of instances at runtime which our existing metamodel APIs don't satisfy very well.

  • Knowing that something is an Array (of any element type). Because Array is invariant I can't use is Array<Anything>. The best I have currently is type(instance).declaration == class Array`` which is hardly egronomic and (given all I really need to do is an instanceof must perform terribly too).
  • Distingushing a Span from a Measure. Because Span and Measure are not shared from the language module I can't use is Span<Integer> for example, because uttering Span is verboten. My work around for this is the positively spine chilling type(instance).declaration.qualifiedName == "ceylon.language::Span".
@tombentley tombentley added this to the 1.2 milestone May 25, 2015
@tombentley
Copy link
Member Author

Oh, and another related thing, as the above examples demonstrate, I end up going type(instance).declaration a lot. This requires construction of a ClassModel just to obtain it's ClassDeclaration. Having a ClassDeclaration classDeclaration(Anything instance) we could avoid that.

@gavinking
Copy link
Member

@tombentley why can't you use is Array<out Anything> array ??

@gavinking
Copy link
Member

Having a ClassDeclaration classDeclaration(Anything instance) we could avoid that.

That would be nice, I agree.

@tombentley
Copy link
Member Author

@tombentley why can't you use is Array<out Anything> array ??

Because I keep forgetting we have use-site variance I suppose.

@tombentley
Copy link
Member Author

@gavinking is there a reason why Span and Measure can't be shared? I know we don't want people to instantiate them directly (but use span() and measure()), but we could make them sealed. That way at least we can refer to their type.

@gavinking
Copy link
Member

Well, so we can change that design later. I mean there's not really a huge difference between a "span" and a "measure", they are much the same thing.

@FroMage
Copy link
Member

FroMage commented Jun 16, 2015

Moving to 1.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants