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

[Bug]: Internal Compiler Error when accessing member of union type #3125

Closed
4 tasks done
I-Al-Istannen opened this issue Apr 5, 2024 · 4 comments
Closed
4 tasks done
Assignees
Labels
bug Something isn't working triaged:core
Milestone

Comments

@I-Al-Istannen
Copy link

Describe the bug

Sometimes two union types share a property; either by inheritance, spreading or coincidence. In these cases I would like to access the type of the shared field, as this operation should be well-defined.

I did not find any match for UnionExpression in the issues/discussion, so I hope this is not a dupe.

Reproduction

Playground or inline:

model A {
  foo: string;
}

model B {
  foo: string;
}

alias OneOfThem = A | B;

alias Usage = {
  a: OneOfThem.foo;
};

Checklist

@timotheeguerin
Copy link
Member

Hi @I-Al-Istannen, thanks for the bug report. Crashing here is definitely not something that should happen however that reference is not doing exactly what you think it is. Unlike in TypeScript where you could do that because it would reference the type of the foo property(string). In TypeSpec it does actually reference the property example playground. This distinction makes it a bit harder to get a meaningful type. We might still be able a virtual union here that is A.foo | B.foo but I think that would require some design.

@I-Al-Istannen
Copy link
Author

I-Al-Istannen commented Apr 6, 2024

Thanks! Yea, the ICE is not good in any case :P The union would work out in many cases, I assume (as properties with the same name tend to be of similar type and shape), but I am not sure it is worth the effort.

I don't quite grasp the type system of TypeSpec it seems, but I have opened a discussion for that. I don't think it has a real place in this issue :)

@markcowl markcowl added this to the [2024] May milestone Apr 8, 2024
@timotheeguerin timotheeguerin self-assigned this Apr 18, 2024
@timotheeguerin
Copy link
Member

Fixed crash in #3188

@I-Al-Istannen
Copy link
Author

Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triaged:core
Projects
None yet
Development

No branches or pull requests

3 participants