microsoft / typespec

https://typespec.io/
MIT License
4.45k stars 208 forks source link

[Bug]: vscode: invalid const assignment causes type hints to fail #4545

Open Arithmomaniac opened 3 weeks ago

Arithmomaniac commented 3 weeks ago

Describe the bug

If the declared type and the assigned type of a const are misaligned, then when the const is used elsewhere, the type hint says "(error)" instead of showing the declared type:

image

I would expect to see "const foobad1: { Bar : string }".

Reproduction

Drop this into VSCode and mouse over foobad1:

const foobad1 : {Bar : string} = #{Bar: 7};

@example(foobad1)
model Foo { Bar : string; }

Checklist

Arithmomaniac commented 1 week ago

A variation of this problem is that if you assign such an object as the return type of an opExample, not only does the mouseover say (error), you get the following error on the returnType assignment:

ErrorType refers to a type, but is being used as a value here. TypeSpec(expect-value)

Reproduction: Playground