[Bug]: Crash when spreading a model that doesn't exist due to Versioning
tjprescott opened this issue · comments
Describe the bug
The following TypeSpec crashes.
@added(Versions.v2)
model MyOptions {
blah: string;
}
@added(Versions.v1)
@put op foo(
...MyOptions
): Foo;
Here we are trying to spread in a model that doesn't exist until v2. Since we cannot decorate the spread operation, this seems like a reasonable approach if you are trying to avoid having two versions of the operation with @added
and @removed
(which has it's own issues). This should arguably be treated like spreading in an empty model, which works fine.
Reproduction
Checklist
- Follow our Code of Conduct
- Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.
Agree this should not crash. Not sure I agree that it should behave as an empty model in this case. You could argue that because spread of an empty model is a no-op, it's ok, but I'm more concerned about treating spread differently from other kinds of references. It may make it hard to reason about what the behavior is going to be when referencing a type which doesn't exist at a particular version.
@bterlson Would you prefer a diagnostic in this case then?
IIRC, the suggested path forward to be to treat it like spreading never
which should trigger an existing diagnostic. Though my concern would be that it doesn't actually unblock the original scenario and necessitates some ugly workarounds.