Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/compiler",
"comment": "**Fix** `unsupported-default` diagnostic showing at the wrong location",
"type": "none"
}
],
"packageName": "@typespec/compiler"
}
4 changes: 2 additions & 2 deletions packages/compiler/core/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2978,8 +2978,8 @@ export function createChecker(program: Program): Checker {
reportCheckerDiagnostic(
createDiagnostic({
code: "unsupported-default",
format: { type: type.kind },
target: defaultType,
format: { type: defaultType.kind },
target: defaultNode,
})
);
return errorType;
Expand Down
16 changes: 16 additions & 0 deletions packages/compiler/test/checker/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
createTestHost,
expectDiagnosticEmpty,
expectDiagnostics,
extractCursor,
TestHost,
} from "../../testing/index.js";

Expand Down Expand Up @@ -149,6 +150,21 @@ describe("compiler: models", () => {
}
});

it(`emit diagnostic when using non value type as default value`, async () => {
const { source, pos } = extractCursor(`
model Foo<D> {
prop?: string = ┆D;
}
`);
testHost.addTypeSpecFile("main.tsp", source);
const diagnostics = await testHost.diagnose("main.tsp");
expectDiagnostics(diagnostics, {
code: "unsupported-default",
message: "Default must be have a value type but has type 'TemplateParameter'.",
pos,
});
});

it(`doesn't emit unsupported-default diagnostic when type is an error`, async () => {
testHost.addTypeSpecFile(
"main.tsp",
Expand Down